Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Boost.Hana: boost::hana::tuple< Xn > Struct Template Reference

Boost , ,

Boost.Hana  1.0.1
Your standard library for metaprogramming
Гетерогенная последовательность на основе индекса общего назначения с фиксированной длиной.

Кортеж — это хлеб и масло для статического метапрограммирования. Концептуально он похож на std::tuple; это контейнер, способный удерживать объекты разных типов и размер которого фиксируется в компиляционное время. Тем не менее, набор Hana обеспечивает гораздо больше функциональности, чем его аналог std, и он также намного более эффективен, чем все стандартные реализации библиотеки, протестированные до сих пор.

Трубочки представляют собой индексные последовательности. Если вам нужна ассоциативная последовательность с доступом на основе ключа, вам следует рассмотреть hana::map или hana::set.

Modeled concepts

Последовательность и все понятия, которые она уточняет

Provided operators

Для удобства предоставляются следующие операторы:

xs == ys -> equal(xs, ys)
xs != ys -> not_equal(xs, ys)
xs < ys -> less(xs, ys)
xs <= ys -> less_equal(xs, ys)
xs > ys -> greater(xs, ys)
xs >= ys -> greater_equal(xs, ys)
xs | f -> chain(xs, f)
xs[n] -> at(xs, n)

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
struct Fish { std::string name; };
struct Cat { std::string name; };
struct Dog { std::string name; };
int main() {
hana::tuple<Fish, Cat, Dog> animals{{"Nemo"}, {"Garfield"}, {"Snoopy"}};
animals[0_c].name = "Moby Dick"; // can modify elements in place, like std::tuple
auto names = hana::transform(animals, [](auto a) {
return a.name;
});
BOOST_HANA_RUNTIME_CHECK(names == hana::make_tuple("Moby Dick", "Garfield", "Snoopy"));
}
+ Inheritance diagram for boost::hana::tuple< Xn >:

Synopsis of associated functions

template<>
constexpr auto make< tuple_tag >
 Function object for creating a tuple. More...
 
constexpr auto make_tuple = make<tuple_tag>
 Alias to make<tuple_tag>; provided for convenience. More...
 
constexpr auto to_tuple = to<tuple_tag>
 Equivalent to to<tuple_tag>; provided for convenience. More...
 
template<typename... T>
constexpr implementation_defined tuple_t {}
 Create a tuple specialized for holding hana::types. More...
 
template<typename T , T... v>
constexpr implementation_defined tuple_c {}
 Create a tuple specialized for holding hana::integral_constants. More...
 

Friends

template<typename... T, typename F >
constexpr auto operator| (tuple< T... >, F)
 Equivalent to hana::chain.
 
template<typename X , typename Y >
constexpr auto operator== (X &&x, Y &&y)
 Equivalent to hana::equal
 
template<typename X , typename Y >
constexpr auto operator!= (X &&x, Y &&y)
 Equivalent to hana::not_equal
 
template<typename X , typename Y >
constexpr auto operator< (X &&x, Y &&y)
 Equivalent to hana::less
 
template<typename X , typename Y >
constexpr auto operator> (X &&x, Y &&y)
 Equivalent to hana::greater
 
template<typename X , typename Y >
constexpr auto operator<= (X &&x, Y &&y)
 Equivalent to hana::less_equal
 
template<typename X , typename Y >
constexpr auto operator>= (X &&x, Y &&y)
 Equivalent to hana::greater_equal
 

Public Member Functions

constexpr tuple ()
 Default constructs the tuple. Only exists when all the elements of the tuple are default constructible.
 
constexpr tuple (Xn const &...xn)
 Initialize each element of the tuple with the corresponding element from xn.... Only exists when all the elements of the tuple are copy-constructible. More...
 
template<typename... Yn>
constexpr tuple (Yn &&...yn)
 Initialize each element of the tuple by perfect-forwarding the corresponding element in yn.... Only exists when all the elements of the created tuple are constructible from the corresponding perfect-forwarded value. More...
 
template<typename... Yn>
constexpr tuple (tuple< Yn... > const &other)
 Copy-initialize a tuple from another tuple. Only exists when all the elements of the constructed tuple are copy-constructible from the corresponding element in the source tuple.
 
template<typename... Yn>
constexpr tuple (tuple< Yn... > &&other)
 Move-initialize a tuple from another tuple. Only exists when all the elements of the constructed tuple are move-constructible from the corresponding element in the source tuple.
 
template<typename... Yn>
constexpr tupleoperator= (tuple< Yn... > const &other)
 Assign a tuple to another tuple. Only exists when all the elements of the destination tuple are assignable from the corresponding element in the source tuple.
 
template<typename... Yn>
constexpr tupleoperator= (tuple< Yn... > &&other)
 Move-assign a tuple to another tuple. Only exists when all the elements of the destination tuple are move-assignable from the corresponding element in the source tuple.
 
template<typename N >
decltype(auto) constexpr operator[] (N &&n)
 Equivalent to hana::at
 

Associated functions

template<typename... Xn>
template<>
constexpr auto make< tuple_tag >
related
Initial value:
= [](auto&& ...xs) {
return tuple<std::decay_t<decltype(xs)>...>{forwarded(xs)...};
}

Функциональный объект для создания tuple.

Учитывая ноль или более объектов xs..., make<tuple_tag> возвращает новый кортеж, содержащий эти объекты. Элементы удерживаются внутри полученного кортежа, и поэтому они копируются или перемещаются. Это аналогично std::make_tuple для создания канавок Ханы.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <string>
namespace hana = boost::hana;
int main() {
auto xs = hana::make<hana::tuple_tag>(1, 2, '3', std::string{"456"});
constexpr auto ys = hana::make<hana::tuple_tag>(1, '2', 3.456);
static_assert(ys == hana::make_tuple(1, '2', 3.456), "");
}
template<typename... Xn>
constexpr auto make_tuple = make<tuple_tag>
related

Alias to make<tuple_tag>; предоставляется для удобства.

template<typename... Xn>
constexpr auto to_tuple = to<tuple_tag>
related

Эквивалент to<tuple_tag>; предусмотрен для удобства.

template<typename... Xn>
template<typename... T>
constexpr implementation_defined tuple_t {}
related

Создайте кортеж, специализированный для проведения hana::types.

Это функционально эквивалентно make<tuple_tag>(type_c...), за исключением использования tuple_t Это позволяет библиотеке выполнять оптимизацию времени компиляции. Также обратите внимание, что тип объектов, возвращаемых tuple_t и эквивалентный вызов make<tuple_tag>, могут отличаться.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
hana::to_tuple(hana::tuple_t<int, char, void, int(float)>)
==
hana::make_tuple(hana::type_c<int>, hana::type_c<char>, hana::type_c<void>, hana::type_c<int(float)>)
);
}
template<typename... Xn>
template<typename T , T... v>
constexpr implementation_defined tuple_c {}
related

Создайте кортеж, специализированный для проведения hana::integral_constants.

Это функционально эквивалентно make<tuple_tag>(integral_c...), за исключением использования tuple_c Это позволяет библиотеке выполнять оптимизацию времени компиляции. Также обратите внимание, что тип объектов, возвращаемых tuple_c и эквивалентный вызов make<tuple_tag>, могут отличаться.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
hana::to_tuple(hana::tuple_c<int, 0, 1, 2>)
==
hana::make_tuple(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>)
);
BOOST_HANA_CONSTANT_CHECK(hana::front(hana::tuple_c<int, 0, 1, 2>) == hana::int_c<0>);
}

Constructor & Destructor Documentation

template<typename... Xn>
constexpr boost::hana::tuple< Xn >::tuple ( Xn const &...  xn)

Инициировать каждый элемент кортежа с соответствующим элементом из xn.... Существует только тогда, когда все элементы кортежа являются копируемыми.

Note
Unlike the corresponding constructor for std::tuple, this constructor is not explicit. This allows returning a tuple from a function with the brace-initialization syntax.
template<typename... Xn>
template<typename... Yn>
constexpr boost::hana::tuple< Xn >::tuple ( Yn &&...  yn)

Инициализируйте каждый элемент кортежа, передав соответствующий элемент в yn.... Существует только тогда, когда все элементы созданного кортежа конструируются из соответствующего совершенного переднего значения.

Note
Unlike the corresponding constructor for std::tuple, this constructor is not explicit. This allows returning a tuple from a function with the brace-initialization syntax.

Статья Boost.Hana: boost::hana::tuple< Xn > Struct Template Reference раздела может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-20 02:40:09/0.005126953125/0