diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/yap/test/value.cpp | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/yap/test/value.cpp')
-rw-r--r-- | src/boost/libs/yap/test/value.cpp | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/src/boost/libs/yap/test/value.cpp b/src/boost/libs/yap/test/value.cpp new file mode 100644 index 00000000..5ca933af --- /dev/null +++ b/src/boost/libs/yap/test/value.cpp @@ -0,0 +1,208 @@ +// Copyright (C) 2016-2018 T. Zachary Laine +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +#include <boost/yap/expression.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/test/minimal.hpp> + + +template<typename T> +using term = boost::yap::terminal<boost::yap::expression, T>; + +template<typename T> +using ref = boost::yap::expression_ref<boost::yap::expression, T>; + +namespace yap = boost::yap; +namespace bh = boost::hana; + + +template<boost::yap::expr_kind Kind, typename Tuple> +struct user_expr +{ + static boost::yap::expr_kind const kind = Kind; + + Tuple elements; +}; + +BOOST_YAP_USER_BINARY_OPERATOR(plus, user_expr, user_expr) + +template<typename T> +using user_term = boost::yap::terminal<user_expr, T>; + +template<typename T> +using user_ref = boost::yap::expression_ref<user_expr, T>; + + +int test_main(int, char * []) +{ + { + { + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(1.0)), double &&>)); + BOOST_CHECK(yap::value(1.0) == 1.0); + } + + { + double d = 2.0; + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(d)), double &>)); + BOOST_CHECK(yap::value(d) == 2.0); + } + + { + double const d = 3.0; + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(d)), double const &>)); + BOOST_CHECK(yap::value(d) == 3.0); + } + } + + { + { + term<double> td = {{1.0}}; + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(std::move(td))), double &&>)); + BOOST_CHECK(yap::value(std::move(td)) == 1.0); + } + + { + term<double> td = {{2.0}}; + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(td)), double &>)); + BOOST_CHECK(yap::value(td) == 2.0); + } + + { + term<double> const td = {{3.0}}; + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(td)), double const &>)); + BOOST_CHECK(yap::value(td) == 3.0); + } + + term<double> unity = {{1.0}}; + using plus_expr_type = yap::expression< + yap::expr_kind::plus, + bh::tuple<ref<term<double> &>, term<int>>>; + plus_expr_type plus_expr = unity + term<int>{{1}}; + + { + ref<term<double> &> ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(std::move(ref))), double &>)); + } + + { + ref<term<double> &> ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(ref)), double &>)); + } + + { + ref<term<double> &> const ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(ref)), double &>)); + } + + { + term<double> const unity = {{1.0}}; + yap::expression< + yap::expr_kind::plus, + bh::tuple<ref<term<double> const &>, term<int>>> + plus_expr = unity + term<int>{{1}}; + + { + ref<term<double> const &> ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT((std::is_same< + decltype(yap::value(std::move(ref))), + double const &>)); + } + + { + ref<term<double> const &> ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(ref)), double const &>)); + } + + { + ref<term<double> const &> const ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(ref)), double const &>)); + } + } + } + + { + { + user_term<double> td = {{1.0}}; + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(std::move(td))), double &&>)); + BOOST_CHECK(yap::value(std::move(td)) == 1.0); + } + + { + user_term<double> td = {{2.0}}; + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(td)), double &>)); + BOOST_CHECK(yap::value(td) == 2.0); + } + + { + user_term<double> const td = {{3.0}}; + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(td)), double const &>)); + BOOST_CHECK(yap::value(td) == 3.0); + } + + user_term<double> unity = {{1.0}}; + using plus_expr_type = user_expr< + yap::expr_kind::plus, + bh::tuple<user_ref<user_term<double> &>, user_term<int>>>; + plus_expr_type plus_expr = unity + user_term<int>{{1}}; + + { + user_ref<user_term<double> &> ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(std::move(ref))), double &>)); + } + + { + user_ref<user_term<double> &> ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(ref)), double &>)); + } + + { + user_ref<user_term<double> &> const ref = bh::front(plus_expr.elements); + BOOST_MPL_ASSERT((std::is_same<decltype(yap::value(ref)), double &>)); + } + + { + user_term<double> const unity = {{1.0}}; + user_expr< + yap::expr_kind::plus, + bh::tuple<user_ref<user_term<double> const &>, user_term<int>>> + plus_expr = unity + user_term<int>{{1}}; + + { + user_ref<user_term<double> const &> ref = + bh::front(plus_expr.elements); + BOOST_MPL_ASSERT((std::is_same< + decltype(yap::value(std::move(ref))), + double const &>)); + } + + { + user_ref<user_term<double> const &> ref = + bh::front(plus_expr.elements); + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(ref)), double const &>)); + } + + { + user_ref<user_term<double> const &> const ref = + bh::front(plus_expr.elements); + BOOST_MPL_ASSERT( + (std::is_same<decltype(yap::value(ref)), double const &>)); + } + } + } + + return 0; +} |