From d2f725f6fe602cbd2fc729465d412ea25b0a7673 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Sun, 25 May 2014 11:06:18 -0400 Subject: [PATCH] Add Typelist; an optimized List for types. --- include/boost/hana.hpp | 1 + include/boost/hana/typelist.hpp | 92 +++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 4 ++ test/typelist/comparable.cpp | 25 +++++++++ test/typelist/functor.cpp | 47 +++++++++++++++++ test/typelist/iterable.cpp | 29 +++++++++++ 6 files changed, 198 insertions(+) create mode 100644 include/boost/hana/typelist.hpp create mode 100644 test/typelist/comparable.cpp create mode 100644 test/typelist/functor.cpp create mode 100644 test/typelist/iterable.cpp diff --git a/include/boost/hana.hpp b/include/boost/hana.hpp index 4135fe0bd..37631e05c 100644 --- a/include/boost/hana.hpp +++ b/include/boost/hana.hpp @@ -45,5 +45,6 @@ #include #include #include +#include #endif // !BOOST_HANA_HPP diff --git a/include/boost/hana/typelist.hpp b/include/boost/hana/typelist.hpp new file mode 100644 index 000000000..6b82c3c20 --- /dev/null +++ b/include/boost/hana/typelist.hpp @@ -0,0 +1,92 @@ +/*! + * @file + * Defines `boost::hana::Typelist`. + * + * + * @copyright Louis Dionne 2014 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE.md or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_TYPELIST_HPP +#define BOOST_HANA_TYPELIST_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace boost { namespace hana { + //! @ingroup datatypes + template + struct Typelist { }; + + template + constexpr auto typelist = Typelist{}; + + template + struct Iterable> { + static constexpr auto head_impl(Typelist) + { return type; } + + static constexpr auto tail_impl(Typelist) + { return typelist; } + + static constexpr auto is_empty_impl(Typelist) + { return false_; } + }; + + template <> + struct Iterable> { + static constexpr auto is_empty_impl(Typelist<>) + { return true_; } + }; + + template + struct Functor> : defaults { + template + static constexpr auto fmap_impl(F f, Typelist) + { return list(f(type)...); } + + template