From 44aa641599679ff64a7787ea6e5cdbc86e27f0c4 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 26 Jun 2014 10:38:42 -0400 Subject: [PATCH] List: remove list_t and list_c --- example/integer_list/foldable/count.cpp | 24 +++++++++++++ example/integer_list/foldable/foldr.cpp | 27 ++++++++++++++ example/integer_list/foldable/minimum.cpp | 17 +++++++++ example/{list => integer_list}/partition.cpp | 25 ++++--------- example/{list => integer_list}/take_until.cpp | 11 ++---- .../take_while.cpp} | 6 ++-- example/list/foldable/find.cpp | 11 ++---- example/list/foldable/foldl.cpp | 19 ++-------- example/list/foldable/foldr.cpp | 15 ++------ example/list/functor/fmap.cpp | 16 ++------- example/range/range.cpp | 7 ++-- .../{list => type_list}/foldable/count.cpp | 19 ++++------ example/type_list/foldable/find.cpp | 22 ++++++++++++ example/type_list/foldable/foldl.cpp | 26 ++++++++++++++ .../foldable/minimum_by.cpp} | 5 +-- example/type_list/functor/fmap.cpp | 23 ++++++++++++ example/type_list/partition.cpp | 28 +++++++++++++++ example/type_list/take_until.cpp | 24 +++++++++++++ example/{list => type_list}/take_while.cpp | 15 +++----- include/boost/hana/foldable.hpp | 36 +++++++++---------- include/boost/hana/functor.hpp | 8 ++--- include/boost/hana/iterable.hpp | 4 +-- include/boost/hana/list.hpp | 27 +++++--------- include/boost/hana/type_list.hpp | 4 +++ test/sandbox/function.cpp | 22 +++++------- test/sandbox/matrix.cpp | 8 ++--- 26 files changed, 277 insertions(+), 172 deletions(-) create mode 100644 example/integer_list/foldable/count.cpp create mode 100644 example/integer_list/foldable/foldr.cpp create mode 100644 example/integer_list/foldable/minimum.cpp rename example/{list => integer_list}/partition.cpp (50%) rename example/{list => integer_list}/take_until.cpp (63%) rename example/{list/foldable/minimum_by.cpp => integer_list/take_while.cpp} (72%) rename example/{list => type_list}/foldable/count.cpp (62%) create mode 100644 example/type_list/foldable/find.cpp create mode 100644 example/type_list/foldable/foldl.cpp rename example/{list/foldable/minimum.cpp => type_list/foldable/minimum_by.cpp} (68%) create mode 100644 example/type_list/functor/fmap.cpp create mode 100644 example/type_list/partition.cpp create mode 100644 example/type_list/take_until.cpp rename example/{list => type_list}/take_while.cpp (55%) diff --git a/example/integer_list/foldable/count.cpp b/example/integer_list/foldable/count.cpp new file mode 100644 index 000000000..cb9a46945 --- /dev/null +++ b/example/integer_list/foldable/count.cpp @@ -0,0 +1,24 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include +using namespace boost::hana; +using namespace literals; + + +int main() { + //! [main] + BOOST_HANA_CONSTEXPR_LAMBDA auto odd = [](auto x) { + return x % 2_c != 0_c; + }; + + BOOST_HANA_STATIC_ASSERT(count(odd, integer_list) == 2_c); + BOOST_HANA_STATIC_ASSERT(count(odd, integer_list) == 0_c); + //! [main] +} diff --git a/example/integer_list/foldable/foldr.cpp b/example/integer_list/foldable/foldr.cpp new file mode 100644 index 000000000..6f883cdcb --- /dev/null +++ b/example/integer_list/foldable/foldr.cpp @@ -0,0 +1,27 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include +#include +using namespace boost::hana; +using namespace literals; + + +int main() { + //! [main] + BOOST_HANA_CONSTEXPR_LAMBDA auto numbers = integer_list; + BOOST_HANA_CONSTEXPR_LAMBDA auto negatives = integer_list; + + BOOST_HANA_CONSTEXPR_LAMBDA auto keep_negatives = [](auto n, auto acc) { + return if_(n < 0_c, cons(n, acc), acc); + }; + + BOOST_HANA_STATIC_ASSERT(foldr(keep_negatives, integer_list, numbers) == negatives); + //! [main] +} diff --git a/example/integer_list/foldable/minimum.cpp b/example/integer_list/foldable/minimum.cpp new file mode 100644 index 000000000..3b41ca79b --- /dev/null +++ b/example/integer_list/foldable/minimum.cpp @@ -0,0 +1,17 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +using namespace boost::hana; + + +int main() { + //! [main] + BOOST_HANA_STATIC_ASSERT(minimum(integer_list) == int_<-4>); + //! [main] +} diff --git a/example/list/partition.cpp b/example/integer_list/partition.cpp similarity index 50% rename from example/list/partition.cpp rename to example/integer_list/partition.cpp index e5a99a725..eb54a2dc6 100644 --- a/example/list/partition.cpp +++ b/example/integer_list/partition.cpp @@ -4,40 +4,27 @@ 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 #include #include +#include #include -#include #include -#include using namespace boost::hana; int main() { - //! [fusion] + //! [main] BOOST_HANA_CONSTEXPR_LAMBDA auto odd = [](auto x) { return x % int_<2> != int_<0>; }; BOOST_HANA_STATIC_ASSERT( - partition(odd, list_c) + partition(odd, integer_list) == pair( - list_c, - list_c + integer_list, + integer_list ) ); - //! [fusion] - - //! [mpl] - BOOST_HANA_STATIC_ASSERT( - partition(trait, list_t) - == - pair( - list_t, - list_t - ) - ); - //! [mpl] + //! [main] } diff --git a/example/list/take_until.cpp b/example/integer_list/take_until.cpp similarity index 63% rename from example/list/take_until.cpp rename to example/integer_list/take_until.cpp index 0b8d8d2b5..3bc139108 100644 --- a/example/list/take_until.cpp +++ b/example/integer_list/take_until.cpp @@ -7,9 +7,8 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#include #include -#include -#include using namespace boost::hana; using namespace literals; @@ -17,13 +16,7 @@ using namespace literals; int main() { //! [main] BOOST_HANA_STATIC_ASSERT( - take_until(_ < 2_c, list(3_c, 2_c, 1_c, 0_c)) == list(3_c, 2_c) - ); - - BOOST_HANA_STATIC_ASSERT( - take_until(trait, list_t) - == - list_t + take_until(_ < 2_c, integer_list) == integer_list ); //! [main] } diff --git a/example/list/foldable/minimum_by.cpp b/example/integer_list/take_while.cpp similarity index 72% rename from example/list/foldable/minimum_by.cpp rename to example/integer_list/take_while.cpp index f4d54a83d..90d4c6d0d 100644 --- a/example/list/foldable/minimum_by.cpp +++ b/example/integer_list/take_while.cpp @@ -6,16 +6,16 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#include #include -#include -#include using namespace boost::hana; +using namespace literals; int main() { //! [main] BOOST_HANA_STATIC_ASSERT( - minimum_by(on(_<_, sizeof_), list_t) == type + take_while(_ < 2_c, integer_list) == integer_list ); //! [main] } diff --git a/example/list/foldable/find.cpp b/example/list/foldable/find.cpp index 48a1ca31b..cd42a8f85 100644 --- a/example/list/foldable/find.cpp +++ b/example/list/foldable/find.cpp @@ -7,7 +7,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include -#include #include #include #include @@ -15,14 +14,8 @@ using namespace boost::hana; int main() { - //! [fusion] + //! [main] BOOST_HANA_STATIC_ASSERT(find(trait_, list(1.0, 2, '3')) == just(2)); BOOST_HANA_STATIC_ASSERT(find(trait_, list(1.0, 2, '3')) == nothing); - //! [fusion] - - //! [mpl] - BOOST_HANA_CONSTEXPR_LAMBDA auto types = list_t; - BOOST_HANA_STATIC_ASSERT(find(_ == type, types) == just(type)); - BOOST_HANA_STATIC_ASSERT(find(_ == type, types) == nothing); - //! [mpl] + //! [main] } diff --git a/example/list/foldable/foldl.cpp b/example/list/foldable/foldl.cpp index e5715278c..59fe28dc8 100644 --- a/example/list/foldable/foldl.cpp +++ b/example/list/foldable/foldl.cpp @@ -4,13 +4,7 @@ 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 -#include -#include -#include #include -#include -#include #include #include @@ -19,7 +13,7 @@ using namespace boost::hana; int main() { - //! [fusion] + //! [main] auto to_string = [](auto x) { return (std::ostringstream{} << x).str(); }; auto show = [=](auto x, auto y) { @@ -27,14 +21,5 @@ int main() { }; assert(foldl(show, "1", list(2, "3", '4')) == "(((1 + 2) + 3) + 4)"); - //! [fusion] - - //! [mpl] - BOOST_HANA_CONSTEXPR_LAMBDA auto types = list_t; - BOOST_HANA_CONSTEXPR_LAMBDA auto count_if_float = [](auto c, auto t) { - return if_(trait(t), c + int_<1>, c); - }; - - BOOST_HANA_STATIC_ASSERT(foldl(count_if_float, int_<0>, types) == int_<4>); - //! [mpl] + //! [main] } diff --git a/example/list/foldable/foldr.cpp b/example/list/foldable/foldr.cpp index 37a8f74a1..cdc87db38 100644 --- a/example/list/foldable/foldr.cpp +++ b/example/list/foldable/foldr.cpp @@ -17,7 +17,7 @@ using namespace boost::hana; int main() { - //! [fusion] + //! [main] auto to_string = [](auto x) { return (std::ostringstream{} << x).str(); }; auto show = [=](auto x, auto y) { @@ -25,16 +25,5 @@ int main() { }; assert(foldr(show, "4", list(1, "2", '3')) == "(1 + (2 + (3 + 4)))"); - //! [fusion] - - //! [mpl] - BOOST_HANA_CONSTEXPR_LAMBDA auto numbers = list_c; - BOOST_HANA_CONSTEXPR_LAMBDA auto negatives = list_c; - - BOOST_HANA_CONSTEXPR_LAMBDA auto keep_negatives = [](auto n, auto acc) { - return if_(n < int_<0>, cons(n, acc), acc); - }; - - BOOST_HANA_STATIC_ASSERT(foldr(keep_negatives, list_c, numbers) == negatives); - //! [mpl] + //! [main] } diff --git a/example/list/functor/fmap.cpp b/example/list/functor/fmap.cpp index d808baa2f..41162be5e 100644 --- a/example/list/functor/fmap.cpp +++ b/example/list/functor/fmap.cpp @@ -4,10 +4,7 @@ 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 -#include #include -#include #include #include @@ -16,8 +13,8 @@ using namespace boost::hana; int main() { - //! [fusion] - BOOST_HANA_CONSTEXPR_LAMBDA auto to_string = [](auto x) { + //! [main] + auto to_string = [](auto x) { return (std::ostringstream{} << x).str(); }; @@ -25,12 +22,5 @@ int main() { fmap(to_string, list(1, '2', "345", std::string{"67"})) == list("1", "2", "345", "67") ); - //! [fusion] - - //! [mpl] - BOOST_HANA_CONSTEXPR_LAMBDA auto types = list_t; - BOOST_HANA_CONSTEXPR_LAMBDA auto pointers = fmap(template_, types); - BOOST_HANA_STATIC_ASSERT(pointers == list_t); - BOOST_HANA_STATIC_ASSERT(head(pointers) == type); - //! [mpl] + //! [main] } diff --git a/example/range/range.cpp b/example/range/range.cpp index d6d3feed8..7459f48e8 100644 --- a/example/range/range.cpp +++ b/example/range/range.cpp @@ -6,14 +6,15 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include #include using namespace boost::hana; +using namespace literals; int main() { //! [main] - BOOST_HANA_STATIC_ASSERT(to(range(int_<0>, int_<5>)) == list_c); - BOOST_HANA_STATIC_ASSERT(to(range(int_<-1>, int_<3>)) == list_c); + BOOST_HANA_STATIC_ASSERT(head(range(0_c, 5_c)) == 0_c); + BOOST_HANA_STATIC_ASSERT(last(range(0_c, 5_c)) == 4_c); + BOOST_HANA_STATIC_ASSERT(tail(range(0_c, 5_c)) == range(1_c, 5_c)); //! [main] } diff --git a/example/list/foldable/count.cpp b/example/type_list/foldable/count.cpp similarity index 62% rename from example/list/foldable/count.cpp rename to example/type_list/foldable/count.cpp index 85155e4d8..9a9bb48e7 100644 --- a/example/list/foldable/count.cpp +++ b/example/type_list/foldable/count.cpp @@ -9,26 +9,19 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include -#include #include +#include + +#include using namespace boost::hana; using namespace literals; int main() { - //! [fusion] - BOOST_HANA_CONSTEXPR_LAMBDA auto odd = [](auto x) { - return x % 2_c != 0_c; - }; - - BOOST_HANA_STATIC_ASSERT(count(odd, list(1_c, 2_c, 3_c)) == 2_c); - BOOST_HANA_STATIC_ASSERT(count(odd, list(1, 2, 3)) == 2); - //! [fusion] - - //! [mpl] - BOOST_HANA_CONSTEXPR_LAMBDA auto types = list_t; + //! [main] + BOOST_HANA_CONSTEXPR_LAMBDA auto types = type_list; BOOST_HANA_STATIC_ASSERT(count(trait, types) == 1_c); BOOST_HANA_STATIC_ASSERT(count(_ == type, types) == 2_c); BOOST_HANA_STATIC_ASSERT(count(_ == type, types) == 0_c); - //! [mpl] + //! [main] } diff --git a/example/type_list/foldable/find.cpp b/example/type_list/foldable/find.cpp new file mode 100644 index 000000000..52a0bd850 --- /dev/null +++ b/example/type_list/foldable/find.cpp @@ -0,0 +1,22 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include +#include +#include +using namespace boost::hana; + + +int main() { + //! [main] + BOOST_HANA_CONSTEXPR_LAMBDA auto types = type_list; + BOOST_HANA_STATIC_ASSERT(find(_ == type, types) == just(type)); + BOOST_HANA_STATIC_ASSERT(find(_ == type, types) == nothing); + //! [main] +} diff --git a/example/type_list/foldable/foldl.cpp b/example/type_list/foldable/foldl.cpp new file mode 100644 index 000000000..f63fc1b4e --- /dev/null +++ b/example/type_list/foldable/foldl.cpp @@ -0,0 +1,26 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include +#include +#include +using namespace boost::hana; +using namespace literals; + + +int main() { + //! [main] + BOOST_HANA_CONSTEXPR_LAMBDA auto types = type_list; + BOOST_HANA_CONSTEXPR_LAMBDA auto count_if_float = [](auto n, auto type) { + return if_(trait(type), n + 1_c, n); + }; + + BOOST_HANA_STATIC_ASSERT(foldl(count_if_float, 0_c, types) == 4_c); + //! [main] +} diff --git a/example/list/foldable/minimum.cpp b/example/type_list/foldable/minimum_by.cpp similarity index 68% rename from example/list/foldable/minimum.cpp rename to example/type_list/foldable/minimum_by.cpp index 559f2cd10..2186f2eb7 100644 --- a/example/list/foldable/minimum.cpp +++ b/example/type_list/foldable/minimum_by.cpp @@ -5,15 +5,16 @@ Distributed under the Boost Software License, Version 1.0. */ #include -#include +#include #include +#include using namespace boost::hana; int main() { //! [main] BOOST_HANA_STATIC_ASSERT( - minimum(fmap(sizeof_, list_t)) == sizeof(char[1]) + minimum_by(on(_ < _, sizeof_), type_list) == type ); //! [main] } diff --git a/example/type_list/functor/fmap.cpp b/example/type_list/functor/fmap.cpp new file mode 100644 index 000000000..ecf898ba4 --- /dev/null +++ b/example/type_list/functor/fmap.cpp @@ -0,0 +1,23 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include + +#include +using namespace boost::hana; + + +int main() { + //! [main] + BOOST_HANA_CONSTEXPR_LAMBDA auto types = type_list; + BOOST_HANA_CONSTEXPR_LAMBDA auto pointers = fmap(template_, types); + BOOST_HANA_STATIC_ASSERT(pointers == type_list); + BOOST_HANA_STATIC_ASSERT(head(pointers) == type); + //! [main] +} diff --git a/example/type_list/partition.cpp b/example/type_list/partition.cpp new file mode 100644 index 000000000..ee570c53a --- /dev/null +++ b/example/type_list/partition.cpp @@ -0,0 +1,28 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include +#include + +#include +using namespace boost::hana; + + +int main() { + //! [main] + BOOST_HANA_STATIC_ASSERT( + partition(trait, type_list) + == + pair( + type_list, + type_list + ) + ); + //! [main] +} diff --git a/example/type_list/take_until.cpp b/example/type_list/take_until.cpp new file mode 100644 index 000000000..2d5d08be0 --- /dev/null +++ b/example/type_list/take_until.cpp @@ -0,0 +1,24 @@ +/* +@copyright Louis Dionne 2014 +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 +#include +#include +#include + +#include +using namespace boost::hana; + + +int main() { + //! [main] + BOOST_HANA_STATIC_ASSERT( + take_until(trait, type_list) + == + type_list + ); + //! [main] +} diff --git a/example/list/take_while.cpp b/example/type_list/take_while.cpp similarity index 55% rename from example/list/take_while.cpp rename to example/type_list/take_while.cpp index eacab3ab8..e28f4ffde 100644 --- a/example/list/take_while.cpp +++ b/example/type_list/take_while.cpp @@ -6,24 +6,19 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include -#include -#include #include +#include + +#include using namespace boost::hana; -using namespace literals; int main() { //! [main] BOOST_HANA_STATIC_ASSERT( - take_while(_ < 2_c, list(0_c, 1_c, 2_c, 3_c)) == list(0_c, 1_c) - ); - - BOOST_HANA_STATIC_ASSERT( - take_while(trait, list_t) + take_while(trait, type_list) == - list_t + type_list ); //! [main] } diff --git a/include/boost/hana/foldable.hpp b/include/boost/hana/foldable.hpp index c29c5f155..9c30f8cb5 100644 --- a/include/boost/hana/foldable.hpp +++ b/include/boost/hana/foldable.hpp @@ -38,11 +38,11 @@ namespace boost { namespace hana { //! Left-associative fold of a structure using a binary operation. //! @method{Foldable} //! - //! ### Fusion example - //! @snippet example/list/foldable/foldl.cpp fusion + //! ### Example 1 + //! @snippet example/list/foldable/foldl.cpp main //! - //! ### MPL example - //! @snippet example/list/foldable/foldl.cpp mpl + //! ### Example 2 + //! @snippet example/type_list/foldable/foldl.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto foldl = [](auto f, auto state, auto foldable) { return Foldable::instance>::foldl_impl(f, state, foldable); }; @@ -50,11 +50,11 @@ namespace boost { namespace hana { //! Right-associative fold of a structure using a binary operation. //! @method{Foldable} //! - //! ### Fusion example - //! @snippet example/list/foldable/foldr.cpp fusion + //! ### Example 1 + //! @snippet example/list/foldable/foldr.cpp main //! - //! ### MPL example - //! @snippet example/list/foldable/foldr.cpp mpl + //! ### Example 2 + //! @snippet example/integer_list/foldable/foldr.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto foldr = [](auto f, auto state, auto foldable) { return Foldable::instance>::foldr_impl(f, state, foldable); }; @@ -146,7 +146,7 @@ namespace boost { namespace hana { //! @method{Foldable} //! //! ### Example - //! @snippet example/list/foldable/minimum_by.cpp main + //! @snippet example/type_list/foldable/minimum_by.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto minimum_by = [](auto predicate, auto foldable) { return Foldable::instance>::minimum_by_impl(predicate, foldable); }; @@ -155,7 +155,7 @@ namespace boost { namespace hana { //! @method{Foldable} //! //! ### Example - //! @snippet example/list/foldable/minimum.cpp main + //! @snippet example/integer_list/foldable/minimum.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto minimum = [](auto foldable) { return Foldable::instance>::minimum_impl(foldable); }; @@ -192,11 +192,11 @@ namespace boost { namespace hana { //! `predicate` is satisfied. //! @method{Foldable} //! - //! ### Fusion example - //! @snippet example/list/foldable/count.cpp fusion + //! ### Example 1 + //! @snippet example/integer_list/foldable/count.cpp main //! - //! ### MPL example - //! @snippet example/list/foldable/count.cpp mpl + //! ### Example 2 + //! @snippet example/type_list/foldable/count.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto count = [](auto predicate, auto foldable) { return Foldable::instance>::count_impl(predicate, foldable); }; @@ -207,11 +207,11 @@ namespace boost { namespace hana { //! Specifically, returns `just` the first element satisfying the //! `predicate`, or `nothing` if there is no such element. //! - //! ### Fusion example - //! @snippet example/list/foldable/find.cpp fusion + //! ### Example 1 + //! @snippet example/list/foldable/find.cpp main //! - //! ### MPL example - //! @snippet example/list/foldable/find.cpp mpl + //! ### Example 2 + //! @snippet example/type_list/foldable/find.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto find = [](auto predicate, auto foldable) { return Foldable::instance>::find_impl(predicate, foldable); }; diff --git a/include/boost/hana/functor.hpp b/include/boost/hana/functor.hpp index 106cd44e2..2323a5f98 100644 --- a/include/boost/hana/functor.hpp +++ b/include/boost/hana/functor.hpp @@ -45,11 +45,11 @@ namespace boost { namespace hana { //! Maps `f` over a `Functor`. //! @method{Functor} //! - //! ### Fusion example - //! @snippet example/list/functor/fmap.cpp fusion + //! ### Example 1 + //! @snippet example/list/functor/fmap.cpp main //! - //! ### MPL example - //! @snippet example/list/functor/fmap.cpp mpl + //! ### Example 2 + //! @snippet example/type_list/functor/fmap.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto fmap = [](auto f, auto functor) { return Functor::instance>::fmap_impl(f, functor); }; diff --git a/include/boost/hana/iterable.hpp b/include/boost/hana/iterable.hpp index 6fea029f5..9d2e455eb 100644 --- a/include/boost/hana/iterable.hpp +++ b/include/boost/hana/iterable.hpp @@ -70,9 +70,9 @@ namespace boost { namespace hana { instance for a data type, specialize the `foldable_from_iterable` variable template. #### Example 1 - @snippet example/list/foldable/foldl.cpp fusion + @snippet example/list/foldable/foldl.cpp main #### Example 2 - @snippet example/list/foldable/foldr.cpp fusion + @snippet example/integer_list/foldable/foldr.cpp main -------------------------------------------------------------------------- diff --git a/include/boost/hana/list.hpp b/include/boost/hana/list.hpp index 6327cdcb1..e44a69585 100644 --- a/include/boost/hana/list.hpp +++ b/include/boost/hana/list.hpp @@ -27,8 +27,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include // for list_t - #include // for std::is_same @@ -57,7 +55,6 @@ namespace boost { namespace hana { - How to implement iterate and repeat? - Check laws for `Applicative`. - Get rid of the `` include. - - Get rid of `list_t` and `list_c`. */ struct List : typeclass { template @@ -154,11 +151,11 @@ namespace boost { namespace hana { //! @note //! The predicate must return an `Integral`. //! - //! ### Fusion example - //! @snippet example/list/partition.cpp fusion + //! ### Example 1 + //! @snippet example/integer_list/partition.cpp main //! - //! ### MPL example - //! @snippet example/list/partition.cpp mpl + //! ### Example 2 + //! @snippet example/type_list/partition.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto partition = [](auto predicate, auto xs) { return List::instance>::partition_impl(predicate, xs); }; @@ -243,7 +240,7 @@ namespace boost { namespace hana { //! This is equivalent to `take_while` with a negated predicate. //! //! ### Example - //! @snippet example/list/take_until.cpp main + //! @snippet example/integer_list/take_until.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto take_until = [](auto predicate, auto xs) { return List::instance>::take_until_impl(predicate, xs); }; @@ -256,7 +253,7 @@ namespace boost { namespace hana { //! an `Integral`. //! //! ### Example - //! @snippet example/list/take_while.cpp main + //! @snippet example/integer_list/take_while.cpp main BOOST_HANA_CONSTEXPR_LAMBDA auto take_while = [](auto predicate, auto xs) { return List::instance>::take_while_impl(predicate, xs); }; @@ -481,10 +478,10 @@ namespace boost { namespace hana { //! applies the function. //! //! ### Example 1 - //! @snippet example/list/functor/fmap.cpp fusion + //! @snippet example/list/functor/fmap.cpp main //! //! ### Example 2 - //! @snippet example/list/functor/fmap.cpp mpl + //! @snippet example/type_list/functor/fmap.cpp main template struct Functor::instance>> : Functor::fmap_mcd @@ -544,14 +541,6 @@ namespace boost { namespace hana { ////////////////////////////////////////////////////////////////////////// // The List data type ////////////////////////////////////////////////////////////////////////// - template - [[deprecated("use integer_list instead")]] - BOOST_HANA_CONSTEXPR_LAMBDA auto list_c = list(integral...); - - template - [[deprecated("use type_list instead")]] - BOOST_HANA_CONSTEXPR_LAMBDA auto list_t = list(type...); - //! @details //! Generic instance for `Iterable`s. template <> diff --git a/include/boost/hana/type_list.hpp b/include/boost/hana/type_list.hpp index 8f519e835..7e0b647f0 100644 --- a/include/boost/hana/type_list.hpp +++ b/include/boost/hana/type_list.hpp @@ -29,6 +29,10 @@ namespace boost { namespace hana { //! @todo //! - Implement efficient membership testing. //! - Actually provide optimizations. + //! - `TypeList` is not really a `Functor` because the function must + //! map from `Type`s to `Type`s. Should it be modified so that + //! `TypeList` becomesĀ `List` if we try to store something else + //! than `Type`s? The same issue goes for `IntegerList`. struct TypeList { }; namespace operators { diff --git a/test/sandbox/function.cpp b/test/sandbox/function.cpp index b74eb2a51..f8b88de9a 100644 --- a/test/sandbox/function.cpp +++ b/test/sandbox/function.cpp @@ -89,29 +89,23 @@ using namespace literals; int main() { - auto f = function(list_c, list_c)( - [](auto x) { - return x + int_<1>; - } + auto f = function(list(1_c, 2_c, 3_c), list(1_c, 2_c, 3_c, 4_c, 5_c, 6_c))( + [](auto x) { return x + 1_c; } ); - auto g = function(list_c, list_c)( - [](auto x) { - return x + int_<1>; - } + auto g = function(list(1_c, 2_c, 3_c), list(2_c, 3_c, 4_c))( + [](auto x) { return x + 1_c; } ); - auto h = function(list_c, list_c)( - [](auto x) { - return x - int_<1>; - } + auto h = function(list(1_c, 2_c, 3_c), list(0_c, 1_c, 2_c))( + [](auto x) { return x - 1_c; } ); BOOST_HANA_STATIC_ASSERT(f == g); BOOST_HANA_STATIC_ASSERT(f != h); - BOOST_HANA_STATIC_ASSERT(f(1) == int_<2>); + BOOST_HANA_STATIC_ASSERT(f(1) == 2); try { f(6); throw; } catch (std::domain_error) { } - BOOST_HANA_STATIC_ASSERT(frange(f) == list_c); + BOOST_HANA_STATIC_ASSERT(frange(f) == list(4_c, 3_c, 2_c)); } diff --git a/test/sandbox/matrix.cpp b/test/sandbox/matrix.cpp index 7d23c5d24..e56961ff7 100644 --- a/test/sandbox/matrix.cpp +++ b/test/sandbox/matrix.cpp @@ -274,10 +274,10 @@ void test_transpose() { void test_repeat_n() { struct T; BOOST_HANA_STATIC_ASSERT(repeat_n(int_<0>, type) == list()); - BOOST_HANA_STATIC_ASSERT(repeat_n(int_<1>, type) == list_t); - BOOST_HANA_STATIC_ASSERT(repeat_n(int_<2>, type) == list_t); - BOOST_HANA_STATIC_ASSERT(repeat_n(int_<3>, type) == list_t); - BOOST_HANA_STATIC_ASSERT(repeat_n(int_<4>, type) == list_t); + BOOST_HANA_STATIC_ASSERT(repeat_n(int_<1>, type) == list(type)); + BOOST_HANA_STATIC_ASSERT(repeat_n(int_<2>, type) == list(type, type)); + BOOST_HANA_STATIC_ASSERT(repeat_n(int_<3>, type) == list(type, type, type)); + BOOST_HANA_STATIC_ASSERT(repeat_n(int_<4>, type) == list(type, type, type, type)); } void test_determinant() {