Boost.Hana: boost::mpl::list< T > Struct Template Reference

| Boost.Hana 1.7.1 Your standard library for metaprogramming |

boost::mpl::list< T > Struct Template Reference
External adapters » Boost.MPL adapters

## Description

### template<typename ... T>
struct boost::mpl::list< T >

Adapter for Boost.MPL lists.

## Modeled concepts

It is possible for MPL lists to model a couple of concepts. However, because they are only able to hold types, they lack the generality required to model concepts like `Functor`, `Sequence` and other related concepts.

1. `Comparable`
   Two MPL lists are equal if and only if they contain the same number of types, and if all those types are equal.
   // Copyright Louis Dionne 2013-2017
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/ext/boost/mpl/list.hpp>
   #include <boost/hana/not_equal.hpp>
   #include <boost/mpl/list.hpp>
   namespace hana = boost::hana;
   namespace mpl = boost::mpl;
   BOOST_HANA_CONSTANT_CHECK(
   hana::equal(mpl::list2<int, char>{}, mpl::list<int, char>{})
   );
   BOOST_HANA_CONSTANT_CHECK(
   hana::not_equal(mpl::list2<int, char>{}, mpl::list<int, char, float>{})
   );
   int main() { }
   assert.hpp
   Defines macros to perform different kinds of assertions.
   equal.hpp
   Defines boost::hana::equal.
   boost::hana::equal
   constexpr auto equal
   Returns a Logical representing whether x is equal to y.
   Definition: equal.hpp:64
   boost::hana::not_equal
   constexpr auto not_equal
   Returns a Logical representing whether x is not equal to y.
   Definition: not_equal.hpp:54
   BOOST_HANA_CONSTANT_CHECK
   #define BOOST_HANA_CONSTANT_CHECK(...)
   Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...
   Definition: assert.hpp:239
   list.hpp
   Adapts boost::mpl::list for use with Hana.
   boost::hana
   Namespace containing everything in the library.
   Definition: accessors.hpp:20
   not_equal.hpp
   Defines boost::hana::not_equal.
2. `Foldable`
   Folding a MPL list is equivalent to folding it as a `Sequence`.
   // Copyright Louis Dionne 2013-2017
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/ext/boost/mpl/list.hpp>
   #include <boost/hana/ext/std/integral_constant.hpp>
   #include <boost/hana/fold_left.hpp>
   #include <boost/hana/if.hpp>
   #include <boost/hana/integral_constant.hpp>
   #include <boost/hana/plus.hpp>
   #include <boost/hana/type.hpp>
   #include <boost/mpl/list.hpp>
   #include <type_traits>
   namespace hana = boost::hana;
   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),
   count + hana::int_c<1>,
   count
   );
   });
   BOOST_HANA_CONSTANT_CHECK(number_of_floats == hana::int_c<3>);
   int main() { }
   integral_constant.hpp
   Adapts std::integral_constant for use with Hana.
   fold_left.hpp
   Defines boost::hana::fold_left.
   boost::hana::count
   constexpr auto count
   Return the number of elements in the structure that compare equal to a given value.
   Definition: count.hpp:41
   boost::hana::if_
   constexpr auto if_
   Conditionally return one of two values based on a condition.
   Definition: if.hpp:41
   if.hpp
   Defines boost::hana::if_.
   integral_constant.hpp
   Defines boost::hana::integral_constant.
   plus.hpp
   Defines boost::hana::plus.
   type.hpp
   Defines boost::hana::type and related utilities.
3. `Iterable`
   Iterating over a MPL list is just iterating over each of the types it contains, as if it were a `Sequence`.
   // Copyright Louis Dionne 2013-2017
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/drop_front.hpp>
   #include <boost/hana/drop_while.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/ext/boost/mpl/list.hpp>
   #include <boost/hana/ext/std/integral_constant.hpp>
   #include <boost/hana/front.hpp>
   #include <boost/hana/type.hpp>
   #include <boost/mpl/list.hpp>
   #include <type_traits>
   namespace hana = boost::hana;
   namespace mpl = boost::mpl;
   BOOST_HANA_CONSTANT_CHECK(hana::front(mpl::list<int, char, void>{}) == hana::type_c<int>);
   BOOST_HANA_CONSTANT_CHECK(hana::equal(
   hana::drop_front(mpl::list<int, char, void>{}),
   mpl::list<char, void>{}
   ));
   BOOST_HANA_CONSTANT_CHECK(hana::equal(
   hana::drop_while(mpl::list<float, double const, int, float&>{},
   hana::trait<std::is_floating_point>),
   mpl::list<int, float&>{}
   ));
   int main() { }
   drop_front.hpp
   Defines boost::hana::drop_front.
   drop_while.hpp
   Defines boost::hana::drop_while.
   front.hpp
   Defines boost::hana::front.
   boost::hana::front
   constexpr auto front
   Returns the first element of a non-empty iterable.
   Definition: front.hpp:32
   boost::hana::drop_while
   constexpr auto drop_while
   Drop elements from an iterable up to, but excluding, the first element for which the predicate is not...
   Definition: drop_while.hpp:44
   boost::hana::drop_front
   constexpr auto drop_front
   Drop the first n elements of an iterable, and return the rest.
   Definition: drop_front.hpp:47
4. `Searchable`
   A MPL list can be searched as if it were a tuple containing `hana::type`s.
   // Copyright Louis Dionne 2013-2017
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/ext/boost/mpl/list.hpp>
   #include <boost/hana/find.hpp>
   #include <boost/hana/find_if.hpp>
   #include <boost/hana/optional.hpp>
   #include <boost/hana/type.hpp>
   #include <boost/mpl/list.hpp>
   namespace hana = boost::hana;
   namespace mpl = boost::mpl;
   BOOST_HANA_CONSTANT_CHECK(
   hana::find_if(mpl::list<int, float, char const*>{}, hana::equal.to(hana::type_c<float>))
   ==
   hana::just(hana::type_c<float>)
   );
   BOOST_HANA_CONSTANT_CHECK(
   hana::find(mpl::list<int, float, char const*>{}, hana::type_c<void>)
   ==
   hana::nothing
   );
   int main() { }
   find.hpp
   Defines boost::hana::find.
   find_if.hpp
   Defines boost::hana::find_if.
   boost::hana::find
   constexpr auto find
   Finds the value associated to the given key in a structure.
   Definition: find.hpp:44
   boost::hana::find_if
   constexpr auto find_if
   Finds the value associated to the first key satisfying a predicate.
   Definition: find_if.hpp:41
   optional.hpp
   Defines boost::hana::optional.

## Conversion from any <tt>Foldable</tt>

A MPL list can be created from any `Foldable`. More precisely, for a `Foldable` `xs` whose linearization is `[x1, ..., xn]`,

to<ext::boost::mpl::list_tag>(xs) == mpl::list<t1, ..., tn>{}

where `tk` is the type of `xk`, or the type contained in `xk` if `xk` is a `hana::type`.

Warning
  The limitations on the size of `mpl::list`s are inherited by this conversion utility, and hence trying to convert a `Foldable` containing more than BOOST_MPL_LIMIT_LIST_SIZE elements is an error.
  // Copyright Louis Dionne 2013-2017
  // 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 <boost/hana/core/to.hpp>
  #include <boost/hana/ext/boost/mpl/list.hpp>
  #include <boost/hana/tuple.hpp>
  #include <boost/hana/type.hpp>
  #include <boost/mpl/list.hpp>
  #include <type_traits>
  namespace hana = boost::hana;
  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() { }
  to.hpp
  Defines boost::hana::to and related utilities.
  tuple.hpp
  Defines boost::hana::tuple.