diff options
Diffstat (limited to 'src/boost/libs/hana/test/concept/constant')
8 files changed, 388 insertions, 0 deletions
diff --git a/src/boost/libs/hana/test/concept/constant/arithmetic.cpp b/src/boost/libs/hana/test/concept/constant/arithmetic.cpp new file mode 100644 index 000000000..e01403ba3 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/arithmetic.cpp @@ -0,0 +1,29 @@ +// 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 "minimal.hpp" + +#include <boost/hana/tuple.hpp> + +#include <laws/euclidean_ring.hpp> +#include <laws/group.hpp> +#include <laws/monoid.hpp> +#include <laws/ring.hpp> +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant<int, -3>{}, + minimal_constant<int, 0>{}, + minimal_constant<int, 1>{}, + minimal_constant<int, 2>{}, + minimal_constant<int, 3>{} + ); + + hana::test::TestMonoid<minimal_constant_tag<int>>{ints}; + hana::test::TestGroup<minimal_constant_tag<int>>{ints}; + hana::test::TestRing<minimal_constant_tag<int>>{ints}; + hana::test::TestEuclideanRing<minimal_constant_tag<int>>{ints}; +} diff --git a/src/boost/libs/hana/test/concept/constant/comparable.cpp b/src/boost/libs/hana/test/concept/constant/comparable.cpp new file mode 100644 index 000000000..697a2389a --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/comparable.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 "minimal.hpp" + +#include <boost/hana/tuple.hpp> + +#include <laws/comparable.hpp> +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant<int, -3>{}, + minimal_constant<int, 0>{}, + minimal_constant<int, 1>{}, + minimal_constant<int, 2>{}, + minimal_constant<int, 3>{} + ); + + hana::test::TestComparable<minimal_constant_tag<int>>{ints}; +} diff --git a/src/boost/libs/hana/test/concept/constant/laws.cpp b/src/boost/libs/hana/test/concept/constant/laws.cpp new file mode 100644 index 000000000..5b132e3f7 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/laws.cpp @@ -0,0 +1,25 @@ +// 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 "minimal.hpp" + +#include <boost/hana/tuple.hpp> + +#include <laws/constant.hpp> +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant<int, -3>{}, + minimal_constant<int, 0>{}, + minimal_constant<int, 1>{}, + minimal_constant<int, 2>{}, + minimal_constant<int, 3>{} + ); + + constexpr auto convertible_types = hana::tuple_t<int, long, long long>; + + hana::test::TestConstant<minimal_constant_tag<int>>{ints, convertible_types}; +} diff --git a/src/boost/libs/hana/test/concept/constant/logical.cpp b/src/boost/libs/hana/test/concept/constant/logical.cpp new file mode 100644 index 000000000..980273aa8 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/logical.cpp @@ -0,0 +1,191 @@ +// 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 "minimal.hpp" + +#include <boost/hana/and.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/eval_if.hpp> +#include <boost/hana/if.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/not_equal.hpp> +#include <boost/hana/or.hpp> +#include <boost/hana/tuple.hpp> +#include <boost/hana/while.hpp> + +#include <laws/base.hpp> +#include <laws/logical.hpp> +namespace hana = boost::hana; + + +struct invalid { }; + +int main() { + constexpr auto bools = hana::make_tuple( + minimal_constant<bool, false>{}, + minimal_constant<bool, true>{} + ); + + hana::test::TestLogical<minimal_constant_tag<bool>>{bools}; + + + constexpr auto true_ = minimal_constant<bool, true>{}; + constexpr auto false_ = minimal_constant<bool, false>{}; + + // not_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::not_(true_), false_)); + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::not_(false_), true_)); + } + + // and_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(false_), + false_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(false_, invalid{}), + false_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, true_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, true_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, false_, invalid{}), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(false_, invalid{}, invalid{}), + false_ + )); + } + + // or_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_), + false_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(true_, invalid{}), + true_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, false_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, false_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, true_, invalid{}), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(true_, invalid{}, invalid{}), + true_ + )); + } + + // if_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::if_(true_, hana::test::ct_eq<3>{}, hana::test::ct_eq<4>{}), + hana::test::ct_eq<3>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::if_(false_, hana::test::ct_eq<3>{}, hana::test::ct_eq<4>{}), + hana::test::ct_eq<4>{} + )); + } + + // eval_if + { + auto t = [](auto) { return hana::test::ct_eq<2>{}; }; + auto e = [](auto) { return hana::test::ct_eq<3>{}; }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::eval_if(true_, t, invalid{}), + hana::test::ct_eq<2>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::eval_if(false_, invalid{}, e), + hana::test::ct_eq<3>{} + )); + } + + // while_ + { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(hana::test::ct_eq<0>{}), hana::test::ct_eq<0>{}, invalid{}), + hana::test::ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(hana::test::ct_eq<0>{})), hana::test::ct_eq<0>{}, f), + f(hana::test::ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(hana::test::ct_eq<0>{}))), hana::test::ct_eq<0>{}, f), + f(f(hana::test::ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(f(hana::test::ct_eq<0>{})))), hana::test::ct_eq<0>{}, f), + f(f(f(hana::test::ct_eq<0>{}))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(f(f(hana::test::ct_eq<0>{}))))), hana::test::ct_eq<0>{}, f), + f(f(f(f(hana::test::ct_eq<0>{})))) + )); + + // Make sure it can be called with an lvalue state: + auto state = hana::test::ct_eq<0>{}; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(f(f(hana::test::ct_eq<0>{}))))), state, f), + f(f(f(f(hana::test::ct_eq<0>{})))) + )); + } +} diff --git a/src/boost/libs/hana/test/concept/constant/mcd.cpp b/src/boost/libs/hana/test/concept/constant/mcd.cpp new file mode 100644 index 000000000..f45327cdb --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/mcd.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 "minimal.hpp" + +#include <boost/hana/concept/constant.hpp> +#include <boost/hana/value.hpp> +namespace hana = boost::hana; + + +// Make sure we really satisfy Constant. +static_assert(hana::Constant<minimal_constant<int, 0>>::value, ""); +static_assert(hana::Constant<minimal_constant<int, 1>>::value, ""); +static_assert(hana::Constant<minimal_constant<int, 2>>::value, ""); +static_assert(hana::Constant<minimal_constant<int, 3>>::value, ""); + +// Make sure we can use hana::value<> properly. +static_assert(hana::value<minimal_constant<int, 0>>() == 0, ""); +static_assert(hana::value<minimal_constant<int, 1>>() == 1, ""); +static_assert(hana::value<minimal_constant<int, 2>>() == 2, ""); +static_assert(hana::value<minimal_constant<int, 3>>() == 3, ""); + +// Check the equivalence between `value(...)` and `value<decltype(...)>()`. +static_assert(hana::value(minimal_constant<int, 0>{}) == hana::value<minimal_constant<int, 0>>(), ""); +static_assert(hana::value(minimal_constant<int, 1>{}) == hana::value<minimal_constant<int, 1>>(), ""); +static_assert(hana::value(minimal_constant<int, 2>{}) == hana::value<minimal_constant<int, 2>>(), ""); +static_assert(hana::value(minimal_constant<int, 3>{}) == hana::value<minimal_constant<int, 3>>(), ""); + + +int main() { } diff --git a/src/boost/libs/hana/test/concept/constant/minimal.hpp b/src/boost/libs/hana/test/concept/constant/minimal.hpp new file mode 100644 index 000000000..ebc2ae11b --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/minimal.hpp @@ -0,0 +1,45 @@ +// 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) + +#ifndef TEST_CONCEPT_CONSTANT_MINIMAL_HPP +#define TEST_CONCEPT_CONSTANT_MINIMAL_HPP + +#include <boost/hana/concept/constant.hpp> +#include <boost/hana/core/when.hpp> +#include <boost/hana/fwd/core/to.hpp> +#include <boost/hana/value.hpp> + + +template <typename T> +struct minimal_constant_tag { + using value_type = T; +}; + +template <typename T, T v> +struct minimal_constant { + using hana_tag = minimal_constant_tag<T>; + static constexpr T value_ = v; +}; + +namespace boost { namespace hana { + template <typename T> + struct value_impl<minimal_constant_tag<T>> { + template <typename N> + static constexpr T apply() { return N::value_; } + }; + + template <typename T, typename C> + struct to_impl<minimal_constant_tag<T>, C, hana::when< + hana::Constant<C>::value && + hana::is_convertible<typename C::value_type, T>::value + >> + : hana::embedding<hana::is_embedded<typename C::value_type, T>::value> + { + template <typename N> + static constexpr auto apply(N const&) + { return minimal_constant<T, hana::value<N>()>{}; } + }; +}} // end namespace boost::hana + +#endif // !TEST_CONCEPT_CONSTANT_MINIMAL_HPP diff --git a/src/boost/libs/hana/test/concept/constant/orderable.cpp b/src/boost/libs/hana/test/concept/constant/orderable.cpp new file mode 100644 index 000000000..08aba261d --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/orderable.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 "minimal.hpp" + +#include <boost/hana/tuple.hpp> + +#include <laws/orderable.hpp> +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant<int, -3>{}, + minimal_constant<int, 0>{}, + minimal_constant<int, 1>{}, + minimal_constant<int, 2>{}, + minimal_constant<int, 3>{} + ); + + hana::test::TestOrderable<minimal_constant_tag<int>>{ints}; +} diff --git a/src/boost/libs/hana/test/concept/constant/to.cpp b/src/boost/libs/hana/test/concept/constant/to.cpp new file mode 100644 index 000000000..8500b1d90 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/to.cpp @@ -0,0 +1,21 @@ +// 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 "minimal.hpp" + +#include <boost/hana/concept/constant.hpp> +#include <boost/hana/core/to.hpp> +namespace hana = boost::hana; + + +static_assert(hana::is_convertible<minimal_constant_tag<bool>, bool>::value, ""); +static_assert(hana::to<bool>(minimal_constant<bool, true>{}) == true, ""); + +static_assert(hana::is_convertible<minimal_constant_tag<int>, int>::value, ""); +static_assert(hana::to<int>(minimal_constant<int, 1>{}) == 1, ""); + +static_assert(hana::is_convertible<minimal_constant_tag<long>, long>::value, ""); +static_assert(hana::to<long>(minimal_constant<long, 1>{}) == 1l, ""); + +int main() { } |