1 // Copyright Louis Dionne 2013-2017 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 4 5 #ifndef BOOST_HANA_TEST_LAWS_COMONAD_HPP 6 #define BOOST_HANA_TEST_LAWS_COMONAD_HPP 7 8 #include <boost/hana/assert.hpp> 9 #include <boost/hana/concept/comonad.hpp> 10 #include <boost/hana/concept/comparable.hpp> 11 #include <boost/hana/core/when.hpp> 12 #include <boost/hana/concept/foldable.hpp> 13 #include <boost/hana/concept/functor.hpp> 14 15 #include <laws/base.hpp> 16 17 18 namespace boost { namespace hana { namespace test { 19 template <typename W, typename = when<true>> 20 struct TestComonad : TestComonad<W, laws> { 21 using TestComonad<W, laws>::TestComonad; 22 }; 23 24 template <typename W> 25 struct TestComonad<W, laws> { 26 template <typename Ws> TestComonadboost::hana::test::TestComonad27 TestComonad(Ws ws) { 28 hana::for_each(ws, [](auto w) { 29 static_assert(Comonad<decltype(w)>{}, ""); 30 31 // extract(duplicate(w)) == w 32 BOOST_HANA_CHECK(hana::equal( 33 hana::extract(hana::duplicate(w)), 34 w 35 )); 36 37 // transform(duplicate(w), extract) == w 38 BOOST_HANA_CHECK(hana::equal( 39 hana::transform(hana::duplicate(w), extract), 40 w 41 )); 42 43 // duplicate(duplicate(w)) == transform(duplicate(w), duplicate) 44 BOOST_HANA_CHECK(hana::equal( 45 hana::duplicate(hana::duplicate(w)), 46 hana::transform(hana::duplicate(w), duplicate) 47 )); 48 }); 49 } 50 }; 51 }}} // end namespace boost::hana::test 52 53 #endif // !BOOST_HANA_TEST_LAWS_COMONAD_HPP 54