// Boost.Geometry // Unit Test // Copyright (c) 2021 Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Use, modification and distribution is subject to 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 #include #include #include #include #include #include #include #include #include #include using point_t = bg::model::point; using linestring_t = bg::model::linestring; using polygon_t = bg::model::polygon; namespace boost { namespace geometry { namespace traits { template <> struct geometry_types { typedef util::type_sequence type; }; #ifndef BOOST_NO_CXX17_HDR_ANY template <> struct geometry_types { typedef util::type_sequence type; }; #endif // BOOST_NO_CXX17_HDR_ANY }}} template void test_all() { DynamicGeometry dg = point_t(1, 2); bg::traits::visit::apply([](auto g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const::value, "Copy of mutable must be visited as mutable."); }, dg); bg::traits::visit::apply([](auto const g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const::value, "Const copy of mutable must be visited as const."); }, dg); bg::traits::visit::apply([](auto & g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Reference of mutable must be visited as mutable."); }, dg); bg::traits::visit::apply([](auto const& g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Const reference of mutable must be visited as const."); }, dg); DynamicGeometry const cdg = point_t(3, 4); bg::traits::visit::apply([](auto g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const::value, "Copy of const must be visited as mutable."); }, cdg); bg::traits::visit::apply([](auto const g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const::value, "Const copy of const must be visited as const."); }, cdg); bg::traits::visit::apply([](auto & g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Reference of const must be visited as const."); }, cdg); bg::traits::visit::apply([](auto const& g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Const reference of const must be visited as const."); }, cdg); bg::traits::visit::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Forward must remain mutable."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); }, dg); bg::traits::visit::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Must remain const."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); }, cdg); bg::traits::visit::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Moved from must remain mutable."); static_assert(std::is_rvalue_reference::value, "Moved from must dynamic geometry must be visited as rvalue reference."); }, std::move(dg)); bg::traits::visit::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Moved from must remain const."); static_assert(std::is_rvalue_reference::value, "Moved from const dynamic geometry must be visited as rvalue reference."); }, std::move(cdg)); bg::traits::visit::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Forwarded temporary dynamic geometry must be mutable."); static_assert(std::is_rvalue_reference::value, "Forwarded temporary dynamic geometry must be visited as rvalue reference."); }, DynamicGeometry{ point_t(1, 2) }); bg::traits::visit::apply([](auto && g1, auto && g2) { BOOST_CHECK(bg::util::is_point::value); BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Forward must remain mutable."); static_assert(std::is_const>::value, "Forward must remain const."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); }, dg, cdg); bg::traits::visit::apply([](auto && g1, auto && g2) { BOOST_CHECK(bg::util::is_point::value); BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Moved from must remain mutable."); static_assert(std::is_const>::value, "Moved from must remain const."); static_assert(std::is_rvalue_reference::value, "Moved from must be visited as rvalue reference."); static_assert(std::is_rvalue_reference::value, "Moved from must be visited as rvalue reference."); }, std::move(dg), std::move(cdg)); bg::traits::visit::apply([](auto && g1, auto && g2) { BOOST_CHECK(bg::util::is_point::value); BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Forward must remain mutable."); static_assert(std::is_const>::value, "Forward must remain const."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); }, cdg, dg); bg::traits::visit::apply([](auto && g1, auto && g2) { BOOST_CHECK(bg::util::is_point::value); BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Moved from must remain mutable."); static_assert(std::is_const>::value, "Moved from must remain const."); static_assert(std::is_rvalue_reference::value, "Moved from must be visited as rvalue reference."); static_assert(std::is_rvalue_reference::value, "Moved from must be visited as rvalue reference."); }, std::move(cdg), std::move(dg)); std::vector v = { DynamicGeometry{ point_t(1, 2) } }; std::vector const cv = { DynamicGeometry{ point_t(1, 2) } }; bg::traits::iter_visit>::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Forward must remain mutable."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); }, v.begin()); bg::traits::iter_visit>::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Forward must remain const."); static_assert(! std::is_rvalue_reference::value, "Forward must collapse to lvalue reference."); }, cv.begin()); bg::traits::iter_visit>::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(! std::is_const>::value, "Moved from must remain mutable."); static_assert(std::is_rvalue_reference::value, "Moved from must be visited as rvalue reference."); }, std::make_move_iterator(v.begin())); bg::traits::iter_visit>::apply([](auto && g) { BOOST_CHECK(bg::util::is_point::value); static_assert(std::is_const>::value, "Moved from must remain const."); static_assert(std::is_rvalue_reference::value, "Moved from must be visited as lvalue reference."); }, std::make_move_iterator(cv.begin())); } int test_main(int, char* []) { test_all(); test_all>(); test_all>(); #ifndef BOOST_NO_CXX17_HDR_ANY test_all(); #endif #ifndef BOOST_NO_CXX17_HDR_VARIANT test_all>(); #endif return 0; }