template<typename ... T>
struct boost::mpl::list< T >
Boost.MPL 列表的适配器。
建模概念
MPL 列表可以建模一些概念。然而,由于它们只能持有类型,因此缺乏建模 Functor、Sequence 和其他相关概念所需的通用性。
Comparable (可比较)
两个 MPL 列表当且仅当它们包含相同数量的类型,并且所有这些类型都相等时才相等。
namespace mpl = boost::mpl;
hana::equal(mpl::list2<int, char>{}, mpl::list<int, char>{})
);
);
int main() { }
constexpr auto equal
返回一个表示 x 是否等于 y 的逻辑值。
定义: equal.hpp:64
constexpr auto not_equal
返回一个表示 x 是否不等于 y 的 Logical。
定义: not_equal.hpp:54
#define BOOST_HANA_CONSTANT_CHECK(...)
等同于 BOOST_HANA_CONSTANT_ASSERT,但不受 BOOST_HANA_CONFIG_DISABLE_ASSERTI... 的影响。
定义: assert.hpp:239
为 Hana 使用而适配 boost::mpl::list。
包含库中所有内容的命名空间。
定义: accessors.hpp:20
定义了 boost::hana::not_equal。
Foldable (可折叠)
折叠 MPL 列表等同于将其作为一个 Sequence 进行折叠。
#include <type_traits>
namespace mpl = boost::mpl;
auto types = mpl::list<long, float, short, float, long, long double>{};
auto number_of_floats = hana::fold_left(types, hana::int_c<0>, [](
auto count,
auto t) {
return hana::if_(hana::trait<std::is_floating_point>(t),
);
});
int main() { }
适配 std::integral_constant 以便与 Hana 一起使用。
定义了 boost::hana::fold_left。
constexpr auto count
返回结构中与给定值相等的元素数量。
定义: count.hpp:41
constexpr auto if_
根据条件有条件地返回两个值之一。
定义: if.hpp:41
定义 boost::hana::integral_constant。
定义 boost::hana::type 和相关工具。
Iterable (可迭代)
遍历 MPL 列表就像遍历其中包含的每个类型一样,就好像它是一个 Sequence。
#include <type_traits>
namespace mpl = boost::mpl;
mpl::list<char, void>{}
));
hana::trait<std::is_floating_point>),
mpl::list<int, float&>{}
));
int main() { }
定义了 boost::hana::drop_front。
定义了 boost::hana::drop_while。
constexpr auto front
返回非空可迭代对象的第一个元素。
定义: front.hpp:32
constexpr auto drop_while
从可迭代对象中删除元素,直到(但不包括)谓词不满足的第一个元素...
定义: drop_while.hpp:44
constexpr auto drop_front
从一个可迭代对象中删除前 n 个元素,并返回剩余的元素。
定义: drop_front.hpp:47
Searchable (可搜索)
MPL 列表可以像包含 hana::type 的元组一样进行搜索。
namespace mpl = boost::mpl;
==
hana::just(hana::type_c<float>)
);
hana::find(mpl::list<int, float, char const*>{}, hana::type_c<void>)
==
hana::nothing
);
int main() { }
定义了 boost::hana::find_if。
constexpr auto find
在结构中查找与给定键关联的值。
定义: find.hpp:44
constexpr auto find_if
查找与满足谓词的第一个键关联的值。
定义: find_if.hpp:41
定义了 boost::hana::optional。
从任意 <tt>Foldable</tt> 转换
MPL 列表可以从任何 Foldable 创建。更确切地说,对于一个线性化为 [x1, ..., xn] 的 Foldable xs,
to<ext::boost::mpl::list_tag>(xs) == mpl::list<t1, ..., tn>{}
其中 tk 是 xk 的类型,或者如果 xk 是 hana::type,则为 xk 所包含的类型。
- 警告
mpl::list 的大小限制会通过此转换工具继承,因此尝试转换包含超过 BOOST_MPL_LIMIT_LIST_SIZE 个元素的 Foldable 是一个错误。
#include <type_traits>
namespace mpl = boost::mpl;
auto xs = hana::make_tuple(hana::type_c<int>, hana::type_c<char>, hana::type_c<double>);
static_assert(std::is_same<
decltype(hana::to<hana::ext::boost::mpl::list_tag>(xs)),
mpl::list<int, char, double>
>{}, "");
int main() { }
定义了 boost::hana::to 和相关工具。