diff options
Diffstat (limited to '')
-rw-r--r-- | src/boost/libs/hana/example/type/alignof.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/basic_type.cpp | 31 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/comparable.cpp | 17 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/decltype.cpp | 20 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/hashable.cpp | 23 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/integral.cpp | 18 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/is_valid.cpp | 31 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/make.cpp | 19 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/metafunction.cpp | 26 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/metafunction_class.cpp | 26 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/sizeof.cpp | 16 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/template.cpp | 26 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/trait.cpp | 17 | ||||
-rw-r--r-- | src/boost/libs/hana/example/type/typeid.cpp | 36 |
14 files changed, 322 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/type/alignof.cpp b/src/boost/libs/hana/example/type/alignof.cpp new file mode 100644 index 000000000..b4fb94525 --- /dev/null +++ b/src/boost/libs/hana/example/type/alignof.cpp @@ -0,0 +1,16 @@ +// 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/equal.hpp> +#include <boost/hana/type.hpp> +namespace hana = boost::hana; + + +struct X { }; +static_assert(hana::alignof_(hana::type_c<X>) == alignof(X), ""); + +static_assert(hana::alignof_(1) == alignof(decltype(1)), ""); +static_assert(hana::alignof_(hana::type_c<int>) == alignof(int), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/basic_type.cpp b/src/boost/libs/hana/example/type/basic_type.cpp new file mode 100644 index 000000000..e3104d655 --- /dev/null +++ b/src/boost/libs/hana/example/type/basic_type.cpp @@ -0,0 +1,31 @@ +// 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/for_each.hpp> +#include <boost/hana/tuple.hpp> +#include <boost/hana/type.hpp> + +#include <boost/core/demangle.hpp> + +#include <cstdlib> +#include <iostream> +#include <string> +namespace hana = boost::hana; + + +// Using hana::type<T> as a parameter type wouldn't work, since it may be +// a dependent type, in which case template argument deduction will fail. +// Using hana::basic_type<T> is fine, since this one is guaranteed to be +// a non dependent base of hana::type<T>. +template <typename T> +std::string const& name_of(hana::basic_type<T>) { + static std::string name = boost::core::demangle(typeid(T).name()); + return name; +} + +int main() { + hana::for_each(hana::tuple_t<int, char, void, std::string>, [](auto type) { + std::cout << name_of(type) << std::endl; + }); +} diff --git a/src/boost/libs/hana/example/type/comparable.cpp b/src/boost/libs/hana/example/type/comparable.cpp new file mode 100644 index 000000000..19eb282bd --- /dev/null +++ b/src/boost/libs/hana/example/type/comparable.cpp @@ -0,0 +1,17 @@ +// 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/not_equal.hpp> +#include <boost/hana/type.hpp> +namespace hana = boost::hana; + + +struct T; +struct U; +BOOST_HANA_CONSTANT_CHECK(hana::type_c<T> == hana::type_c<T>); +BOOST_HANA_CONSTANT_CHECK(hana::type_c<T> != hana::type_c<U>); + +int main() { } diff --git a/src/boost/libs/hana/example/type/decltype.cpp b/src/boost/libs/hana/example/type/decltype.cpp new file mode 100644 index 000000000..45110f1ac --- /dev/null +++ b/src/boost/libs/hana/example/type/decltype.cpp @@ -0,0 +1,20 @@ +// 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/type.hpp> +namespace hana = boost::hana; + + +struct X { }; +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(X{}) == hana::type_c<X>); +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(hana::type_c<X>) == hana::type_c<X>); + +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(1) == hana::type_c<int>); + +static int const& i = 1; +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(i) == hana::type_c<int const>); + +int main() { } diff --git a/src/boost/libs/hana/example/type/hashable.cpp b/src/boost/libs/hana/example/type/hashable.cpp new file mode 100644 index 000000000..eaecfff12 --- /dev/null +++ b/src/boost/libs/hana/example/type/hashable.cpp @@ -0,0 +1,23 @@ +// 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/hash.hpp> +#include <boost/hana/type.hpp> +namespace hana = boost::hana; + + +// `hana::hash` is the identity on `hana::type`s. +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::type_c<int>), + hana::type_c<int> +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::type_c<void>), + hana::type_c<void> +)); + +int main() { } diff --git a/src/boost/libs/hana/example/type/integral.cpp b/src/boost/libs/hana/example/type/integral.cpp new file mode 100644 index 000000000..612665de9 --- /dev/null +++ b/src/boost/libs/hana/example/type/integral.cpp @@ -0,0 +1,18 @@ +// 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/ext/std/integral_constant.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +constexpr auto is_void = hana::integral(hana::metafunction<std::is_void>); +BOOST_HANA_CONSTANT_CHECK(is_void(hana::type_c<void>)); +BOOST_HANA_CONSTANT_CHECK(hana::not_(is_void(hana::type_c<int>))); + +int main() { } diff --git a/src/boost/libs/hana/example/type/is_valid.cpp b/src/boost/libs/hana/example/type/is_valid.cpp new file mode 100644 index 000000000..a683e78f1 --- /dev/null +++ b/src/boost/libs/hana/example/type/is_valid.cpp @@ -0,0 +1,31 @@ +// 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/not.hpp> +#include <boost/hana/type.hpp> + +#include <string> +#include <vector> +namespace hana = boost::hana; + + +int main() { + // Checking for a member + struct Person { std::string name; }; + auto has_name = hana::is_valid([](auto&& p) -> decltype((void)p.name) { }); + + Person joe{"Joe"}; + static_assert(has_name(joe), ""); + static_assert(!has_name(1), ""); + + + // Checking for a nested type + auto has_value_type = hana::is_valid([](auto t) -> hana::type< + typename decltype(t)::type::value_type + > { }); + + static_assert(has_value_type(hana::type_c<std::vector<int>>), ""); + static_assert(!has_value_type(hana::type_c<Person>), ""); +} diff --git a/src/boost/libs/hana/example/type/make.cpp b/src/boost/libs/hana/example/type/make.cpp new file mode 100644 index 000000000..97bb4a11f --- /dev/null +++ b/src/boost/libs/hana/example/type/make.cpp @@ -0,0 +1,19 @@ +// 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/core/make.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/type.hpp> +namespace hana = boost::hana; + + +struct X { }; +BOOST_HANA_CONSTANT_CHECK(hana::make<hana::type_tag>(X{}) == hana::type_c<X>); +BOOST_HANA_CONSTANT_CHECK(hana::make<hana::type_tag>(hana::type_c<X>) == hana::type_c<X>); + +BOOST_HANA_CONSTANT_CHECK(hana::make_type(X{}) == hana::type_c<X>); +BOOST_HANA_CONSTANT_CHECK(hana::make_type(hana::type_c<X>) == hana::type_c<X>); + +int main() { } diff --git a/src/boost/libs/hana/example/type/metafunction.cpp b/src/boost/libs/hana/example/type/metafunction.cpp new file mode 100644 index 000000000..a60d60778 --- /dev/null +++ b/src/boost/libs/hana/example/type/metafunction.cpp @@ -0,0 +1,26 @@ +// 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/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +template <typename ...> struct f { struct type; }; +struct x; +struct y; + +BOOST_HANA_CONSTANT_CHECK(hana::metafunction<f>() == hana::type_c<f<>::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction<f>(hana::type_c<x>) == hana::type_c<f<x>::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction<f>(hana::type_c<x>, hana::type_c<y>) == hana::type_c<f<x, y>::type>); + +static_assert(std::is_same< + decltype(hana::metafunction<f>)::apply<x, y>::type, + f<x, y>::type +>::value, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/metafunction_class.cpp b/src/boost/libs/hana/example/type/metafunction_class.cpp new file mode 100644 index 000000000..f01e26719 --- /dev/null +++ b/src/boost/libs/hana/example/type/metafunction_class.cpp @@ -0,0 +1,26 @@ +// 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/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +struct f { template <typename ...> struct apply { struct type; }; }; +struct x; +struct y; + +BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class<f>() == hana::type_c<f::apply<>::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class<f>(hana::type_c<x>) == hana::type_c<f::apply<x>::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class<f>(hana::type_c<x>, hana::type_c<y>) == hana::type_c<f::apply<x, y>::type>); + +static_assert(std::is_same< + decltype(hana::metafunction_class<f>)::apply<x, y>::type, + f::apply<x, y>::type +>::value, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/sizeof.cpp b/src/boost/libs/hana/example/type/sizeof.cpp new file mode 100644 index 000000000..300015dd2 --- /dev/null +++ b/src/boost/libs/hana/example/type/sizeof.cpp @@ -0,0 +1,16 @@ +// 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/equal.hpp> +#include <boost/hana/type.hpp> +namespace hana = boost::hana; + + +struct X { }; +static_assert(hana::sizeof_(hana::type_c<X>) == sizeof(X), ""); + +static_assert(hana::sizeof_(1) == sizeof(1), ""); +static_assert(hana::sizeof_(hana::type_c<int>) == sizeof(int), ""); + +int main() {} diff --git a/src/boost/libs/hana/example/type/template.cpp b/src/boost/libs/hana/example/type/template.cpp new file mode 100644 index 000000000..3840cc7c0 --- /dev/null +++ b/src/boost/libs/hana/example/type/template.cpp @@ -0,0 +1,26 @@ +// 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/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +template <typename ...> struct f; +struct x; +struct y; + +BOOST_HANA_CONSTANT_CHECK(hana::template_<f>() == hana::type_c<f<>>); +BOOST_HANA_CONSTANT_CHECK(hana::template_<f>(hana::type_c<x>) == hana::type_c<f<x>>); +BOOST_HANA_CONSTANT_CHECK(hana::template_<f>(hana::type_c<x>, hana::type_c<y>) == hana::type_c<f<x, y>>); + +static_assert(std::is_same< + decltype(hana::template_<f>)::apply<x, y>::type, + f<x, y> +>::value, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/trait.cpp b/src/boost/libs/hana/example/type/trait.cpp new file mode 100644 index 000000000..31064bc7b --- /dev/null +++ b/src/boost/libs/hana/example/type/trait.cpp @@ -0,0 +1,17 @@ +// 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/ext/std/integral_constant.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +BOOST_HANA_CONSTANT_CHECK(hana::trait<std::is_integral>(hana::type_c<int>)); +BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::trait<std::is_integral>(hana::type_c<float>))); + +int main() { } diff --git a/src/boost/libs/hana/example/type/typeid.cpp b/src/boost/libs/hana/example/type/typeid.cpp new file mode 100644 index 000000000..f219aec39 --- /dev/null +++ b/src/boost/libs/hana/example/type/typeid.cpp @@ -0,0 +1,36 @@ +// 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/remove_if.hpp> +#include <boost/hana/tuple.hpp> +#include <boost/hana/type.hpp> + +#include <string> +namespace hana = boost::hana; + + +struct Cat { std::string name; }; +struct Dog { std::string name; }; +struct Fish { std::string name; }; + +bool operator==(Cat const& a, Cat const& b) { return a.name == b.name; } +bool operator!=(Cat const& a, Cat const& b) { return a.name != b.name; } +bool operator==(Dog const& a, Dog const& b) { return a.name == b.name; } +bool operator!=(Dog const& a, Dog const& b) { return a.name != b.name; } +bool operator==(Fish const& a, Fish const& b) { return a.name == b.name; } +bool operator!=(Fish const& a, Fish const& b) { return a.name != b.name; } + +int main() { + hana::tuple<Cat, Fish, Dog, Fish> animals{ + Cat{"Garfield"}, Fish{"Jaws"}, Dog{"Beethoven"}, Fish{"Nemo"} + }; + + auto mammals = hana::remove_if(animals, [](auto const& a) { + return hana::typeid_(a) == hana::type<Fish>{}; + }); + + BOOST_HANA_RUNTIME_CHECK(mammals == hana::make_tuple(Cat{"Garfield"}, Dog{"Beethoven"})); +} |