diff --git a/example/core/convert.cpp b/example/core/convert.cpp index 2cd460973..6ba61c455 100644 --- a/example/core/convert.cpp +++ b/example/core/convert.cpp @@ -4,7 +4,7 @@ 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 +#include #include #include #include diff --git a/include/boost/hana/comparable.hpp b/include/boost/hana/comparable.hpp index 9df3f49a2..6c1e5d6ef 100644 --- a/include/boost/hana/comparable.hpp +++ b/include/boost/hana/comparable.hpp @@ -10,113 +10,9 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_COMPARABLE_HPP #define BOOST_HANA_COMPARABLE_HPP -#include -#include -#include - - -namespace boost { namespace hana { - //! @ingroup typeclasses - //! The `Comparable` type class defines equality and inequality. - struct Comparable { - BOOST_HANA_BINARY_TYPECLASS(Comparable); - struct equal_mcd; - struct not_equal_mcd; - struct laws; - }; - - /*! - Returns a `Logical` representing whether `x` is equal to `y`. - @method{Comparable} - - @internal - ### Design choice: arity of `equal` - It is a valid question whether `equal` should accept more than 2 arguments - and have semantics matching those of Python's `==`. This is not supported - right now for the following reasons: - - - It was not shown to be useful so far in the MPL11. - - It does not make sense for `not_equal` to have an arity of more than 2, - so only `equal` could maybe have those semantics. - - Having a binary `equal` makes it possible to use currying. - - `equal(x, y...)` can be implemented as `all(x == _, list(y...))`, which - is pretty straightforward anyway. - */ - BOOST_HANA_CONSTEXPR_LAMBDA auto equal = [](auto x, auto y) { - return Comparable::instance< - datatype_t, datatype_t - >::equal_impl(x, y); - }; - - //! Returns a `Logical` representing whether `x` is not equal to `y`. - //! @method{Comparable} - BOOST_HANA_CONSTEXPR_LAMBDA auto not_equal = [](auto x, auto y) { - return Comparable::instance< - datatype_t, datatype_t - >::not_equal_impl(x, y); - }; - - //! Minimal complete definition : `equal` - struct Comparable::equal_mcd { - template - static constexpr auto not_equal_impl(X x, Y y) - { return not_(equal(x, y)); } - }; - - //! Minimal complete definition : `not_equal` - struct Comparable::not_equal_mcd { - template - static constexpr auto equal_impl(X x, Y y) - { return not_(not_equal(x, y)); } - }; - - //! @details - //! `equal` must define an equivalence relation. In other words, for all - //! `a`, `b`, `c` of comparable data types, - //! @code - //! a == a // Reflexivity - //! if a == b then b == a // Symmetry - //! if a == b && b == c then a == c // Transitivity - //! @endcode - struct Comparable::laws { - template - static constexpr auto check(A a, B b, C c) { - auto implies = [](auto p, auto q) { return or_(not_(p), q); }; - return and_( - equal(a, a), - implies(equal(a, b), equal(b, a)), - implies(and_(equal(a, b), equal(b, c)), equal(a, c)) - ); - } - }; - - //! @details - //! Objects whose data type is the same as their C++ type and who have a - //! valid `operator==` are automatically instances of `Comparable` by - //! using that comparison. - template - struct Comparable::instance> - : Comparable::equal_mcd - { - static constexpr auto equal_impl(X x, Y y) - { return x == y; } - }; - - namespace operators { - //! Equivalent to `equal`. - //! @method{boost::hana::Comparable} - template - constexpr auto operator==(T t, U u) - { return equal(t, u); } - - //! Equivalent to `not_equal`. - //! @method{boost::hana::Comparable} - template - constexpr auto operator!=(T t, U u) - { return not_equal(t, u); } - } -}} // end namespace boost::hana +#include +#include +#include +#include #endif // !BOOST_HANA_COMPARABLE_HPP - -#include diff --git a/include/boost/hana/comparable/comparable.hpp b/include/boost/hana/comparable/comparable.hpp new file mode 100644 index 000000000..80462daa6 --- /dev/null +++ b/include/boost/hana/comparable/comparable.hpp @@ -0,0 +1,86 @@ +/*! +@file +Forward declares `boost::hana::Comparable`. + +@copyright Louis Dionne 2014 +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 BOOST_HANA_COMPARABLE_COMPARABLE_HPP +#define BOOST_HANA_COMPARABLE_COMPARABLE_HPP + +#include +#include +#include + + +namespace boost { namespace hana { + //! @ingroup typeclasses + //! The `Comparable` type class defines equality and inequality. + struct Comparable { + BOOST_HANA_BINARY_TYPECLASS(Comparable); + struct equal_mcd; + struct not_equal_mcd; + struct laws; + }; + + /*! + Returns a `Logical` representing whether `x` is equal to `y`. + @method{Comparable} + + @internal + ### Design choice: arity of `equal` + It is a valid question whether `equal` should accept more than 2 arguments + and have semantics matching those of Python's `==`. This is not supported + right now for the following reasons: + + - It was not shown to be useful so far in the MPL11. + - It does not make sense for `not_equal` to have an arity of more than 2, + so only `equal` could maybe have those semantics. + - Having a binary `equal` makes it possible to use currying. + - `equal(x, y...)` can be implemented as `all(x == _, list(y...))`, which + is pretty straightforward anyway. + */ + BOOST_HANA_CONSTEXPR_LAMBDA auto equal = [](auto x, auto y) { + return Comparable::instance< + datatype_t, datatype_t + >::equal_impl(x, y); + }; + + //! Returns a `Logical` representing whether `x` is not equal to `y`. + //! @method{Comparable} + BOOST_HANA_CONSTEXPR_LAMBDA auto not_equal = [](auto x, auto y) { + return Comparable::instance< + datatype_t, datatype_t + >::not_equal_impl(x, y); + }; + + //! @details + //! Objects whose data type is the same as their C++ type and who have a + //! valid `operator==` are automatically instances of `Comparable` by + //! using that comparison. + template + struct Comparable::instance> + : detail::dependent_on + { + static constexpr auto equal_impl(X x, Y y) + { return x == y; } + }; + + namespace operators { + //! Equivalent to `equal`. + //! @method{boost::hana::Comparable} + template + constexpr auto operator==(T t, U u) + { return equal(t, u); } + + //! Equivalent to `not_equal`. + //! @method{boost::hana::Comparable} + template + constexpr auto operator!=(T t, U u) + { return not_equal(t, u); } + } +}} // end namespace boost::hana + +#endif // !BOOST_HANA_COMPARABLE_COMPARABLE_HPP diff --git a/include/boost/hana/comparable/equal_mcd.hpp b/include/boost/hana/comparable/equal_mcd.hpp new file mode 100644 index 000000000..405decfee --- /dev/null +++ b/include/boost/hana/comparable/equal_mcd.hpp @@ -0,0 +1,29 @@ +/*! +@file +Defines `boost::hana::Comparable::equal_mcd`. + +@copyright Louis Dionne 2014 +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 BOOST_HANA_COMPARABLE_EQUAL_MCD_HPP +#define BOOST_HANA_COMPARABLE_EQUAL_MCD_HPP + +#include + +#include + + +namespace boost { namespace hana { + //! Minimal complete definition : `equal` + struct Comparable::equal_mcd { + template + static constexpr auto not_equal_impl(X x, Y y) + { return not_(equal(x, y)); } + }; +}} // end namespace boost::hana + +#endif // !BOOST_HANA_COMPARABLE_EQUAL_MCD_HPP + +#include diff --git a/include/boost/hana/comparable/laws.hpp b/include/boost/hana/comparable/laws.hpp new file mode 100644 index 000000000..24826c559 --- /dev/null +++ b/include/boost/hana/comparable/laws.hpp @@ -0,0 +1,42 @@ +/*! +@file +Defines `boost::hana::Comparable::laws`. + +@copyright Louis Dionne 2014 +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 BOOST_HANA_COMPARABLE_LAWS_HPP +#define BOOST_HANA_COMPARABLE_LAWS_HPP + +#include + +#include + + +namespace boost { namespace hana { + //! @details + //! `equal` must define an equivalence relation. In other words, for all + //! `a`, `b`, `c` of comparable data types, + //! @code + //! a == a // Reflexivity + //! if a == b then b == a // Symmetry + //! if a == b && b == c then a == c // Transitivity + //! @endcode + struct Comparable::laws { + template + static constexpr auto check(A a, B b, C c) { + auto implies = [](auto p, auto q) { return or_(not_(p), q); }; + return and_( + equal(a, a), + implies(equal(a, b), equal(b, a)), + implies(and_(equal(a, b), equal(b, c)), equal(a, c)) + ); + } + }; +}} // end namespace boost::hana + +#endif // !BOOST_HANA_COMPARABLE_LAWS_HPP + +#include diff --git a/include/boost/hana/comparable/not_equal_mcd.hpp b/include/boost/hana/comparable/not_equal_mcd.hpp new file mode 100644 index 000000000..f757ed98f --- /dev/null +++ b/include/boost/hana/comparable/not_equal_mcd.hpp @@ -0,0 +1,29 @@ +/*! +@file +Defines `boost::hana::Comparable::not_equal_mcd`. + +@copyright Louis Dionne 2014 +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 BOOST_HANA_COMPARABLE_NOT_EQUAL_MCD_HPP +#define BOOST_HANA_COMPARABLE_NOT_EQUAL_MCD_HPP + +#include + +#include + + +namespace boost { namespace hana { + //! Minimal complete definition : `not_equal` + struct Comparable::not_equal_mcd { + template + static constexpr auto equal_impl(X x, Y y) + { return not_(not_equal(x, y)); } + }; +}} // end namespace boost::hana + +#endif // !BOOST_HANA_COMPARABLE_NOT_EQUAL_MCD_HPP + +#include diff --git a/include/boost/hana/detail/laws.hpp b/include/boost/hana/detail/laws.hpp index edd5f7d27..645d0576e 100644 --- a/include/boost/hana/detail/laws.hpp +++ b/include/boost/hana/detail/laws.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_DETAIL_LAWS_HPP #include -#include +#include #include #include #include diff --git a/include/boost/hana/detail/minimal/applicative.hpp b/include/boost/hana/detail/minimal/applicative.hpp index cb9e42a14..44d4b3eaf 100644 --- a/include/boost/hana/detail/minimal/applicative.hpp +++ b/include/boost/hana/detail/minimal/applicative.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_DETAIL_MINIMAL_APPLICATIVE_HPP #include -#include +#include #include diff --git a/include/boost/hana/detail/minimal/comparable.hpp b/include/boost/hana/detail/minimal/comparable.hpp index 5c89fe16e..f2570293c 100644 --- a/include/boost/hana/detail/minimal/comparable.hpp +++ b/include/boost/hana/detail/minimal/comparable.hpp @@ -10,7 +10,8 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_DETAIL_MINIMAL_COMPARABLE_HPP #define BOOST_HANA_DETAIL_MINIMAL_COMPARABLE_HPP -#include +#include +#include namespace boost { namespace hana { diff --git a/include/boost/hana/detail/minimal/functor.hpp b/include/boost/hana/detail/minimal/functor.hpp index 083cf6f39..f28d0c9a0 100644 --- a/include/boost/hana/detail/minimal/functor.hpp +++ b/include/boost/hana/detail/minimal/functor.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_DETAIL_MINIMAL_FUNCTOR_HPP #define BOOST_HANA_DETAIL_MINIMAL_FUNCTOR_HPP -#include +#include #include diff --git a/include/boost/hana/detail/minimal/iterable.hpp b/include/boost/hana/detail/minimal/iterable.hpp index 135648cda..cff725553 100644 --- a/include/boost/hana/detail/minimal/iterable.hpp +++ b/include/boost/hana/detail/minimal/iterable.hpp @@ -11,7 +11,8 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_DETAIL_MINIMAL_ITERABLE_HPP #include -#include +#include +#include #include #include diff --git a/include/boost/hana/detail/minimal/monad.hpp b/include/boost/hana/detail/minimal/monad.hpp index 46bc3512f..a5d0e6b16 100644 --- a/include/boost/hana/detail/minimal/monad.hpp +++ b/include/boost/hana/detail/minimal/monad.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_DETAIL_MINIMAL_MONAD_HPP #include -#include +#include #include #include diff --git a/include/boost/hana/detail/minimal/traversable.hpp b/include/boost/hana/detail/minimal/traversable.hpp index 833051393..6cf58dfbc 100644 --- a/include/boost/hana/detail/minimal/traversable.hpp +++ b/include/boost/hana/detail/minimal/traversable.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_DETAIL_MINIMAL_TRAVERSABLE_HPP #include -#include +#include #include diff --git a/include/boost/hana/detail/sandbox/map.hpp b/include/boost/hana/detail/sandbox/map.hpp index 8eec696ea..34d0976ee 100644 --- a/include/boost/hana/detail/sandbox/map.hpp +++ b/include/boost/hana/detail/sandbox/map.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_MAP_HPP #define BOOST_HANA_MAP_HPP -#include +#include #include #include #include diff --git a/include/boost/hana/detail/sandbox/set.hpp b/include/boost/hana/detail/sandbox/set.hpp index c03c299f3..1756cc903 100644 --- a/include/boost/hana/detail/sandbox/set.hpp +++ b/include/boost/hana/detail/sandbox/set.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_SET_HPP #define BOOST_HANA_SET_HPP -#include +#include #include #include #include diff --git a/include/boost/hana/ext/boost/mpl/list.hpp b/include/boost/hana/ext/boost/mpl/list.hpp index a2ed2e913..e2e961697 100644 --- a/include/boost/hana/ext/boost/mpl/list.hpp +++ b/include/boost/hana/ext/boost/mpl/list.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_EXT_BOOST_MPL_LIST_HPP #include -#include +#include #include #include #include diff --git a/include/boost/hana/ext/boost/mpl/vector.hpp b/include/boost/hana/ext/boost/mpl/vector.hpp index e96c1b934..63467f297 100644 --- a/include/boost/hana/ext/boost/mpl/vector.hpp +++ b/include/boost/hana/ext/boost/mpl/vector.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_EXT_BOOST_MPL_VECTOR_HPP #include -#include +#include #include #include #include diff --git a/include/boost/hana/ext/std/integer_sequence.hpp b/include/boost/hana/ext/std/integer_sequence.hpp index 9929669a1..d26714957 100644 --- a/include/boost/hana/ext/std/integer_sequence.hpp +++ b/include/boost/hana/ext/std/integer_sequence.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_EXT_STD_INTEGER_SEQUENCE_HPP #include -#include +#include #include #include #include diff --git a/include/boost/hana/foldable.hpp b/include/boost/hana/foldable.hpp index 577efd386..c99c2fb44 100644 --- a/include/boost/hana/foldable.hpp +++ b/include/boost/hana/foldable.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_FOLDABLE_HPP #include -#include +#include #include #include #include diff --git a/include/boost/hana/integral.hpp b/include/boost/hana/integral.hpp index 61703bcfc..c9e4de284 100644 --- a/include/boost/hana/integral.hpp +++ b/include/boost/hana/integral.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_INTEGRAL_HPP #define BOOST_HANA_INTEGRAL_HPP -#include +#include #include #include #include diff --git a/include/boost/hana/iterable.hpp b/include/boost/hana/iterable.hpp index 76e3a1476..2005b2385 100644 --- a/include/boost/hana/iterable.hpp +++ b/include/boost/hana/iterable.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_ITERABLE_HPP #define BOOST_HANA_ITERABLE_HPP -#include +#include #include #include #include diff --git a/include/boost/hana/list.hpp b/include/boost/hana/list.hpp index 8b69b69df..080c5b963 100644 --- a/include/boost/hana/list.hpp +++ b/include/boost/hana/list.hpp @@ -12,7 +12,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include +#include #include #include #include diff --git a/include/boost/hana/maybe.hpp b/include/boost/hana/maybe.hpp index e4879efdc..f827c493d 100644 --- a/include/boost/hana/maybe.hpp +++ b/include/boost/hana/maybe.hpp @@ -12,7 +12,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include +#include #include #include #include diff --git a/include/boost/hana/pair.hpp b/include/boost/hana/pair.hpp index 57a6eba85..29bfdfcea 100644 --- a/include/boost/hana/pair.hpp +++ b/include/boost/hana/pair.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_PAIR_HPP #define BOOST_HANA_PAIR_HPP -#include +#include #include #include #include diff --git a/include/boost/hana/range.hpp b/include/boost/hana/range.hpp index 80521caf4..1e54ef15a 100644 --- a/include/boost/hana/range.hpp +++ b/include/boost/hana/range.hpp @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_RANGE_HPP #define BOOST_HANA_RANGE_HPP -#include +#include #include #include #include diff --git a/include/boost/hana/type.hpp b/include/boost/hana/type.hpp index ae680a0aa..b483fb322 100644 --- a/include/boost/hana/type.hpp +++ b/include/boost/hana/type.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_TYPE_HPP #include -#include +#include #include #include #include diff --git a/include/boost/hana/type_list.hpp b/include/boost/hana/type_list.hpp index 24053efa4..e5ce8a89b 100644 --- a/include/boost/hana/type_list.hpp +++ b/include/boost/hana/type_list.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define BOOST_HANA_TYPE_LIST_HPP #include -#include +#include #include #include #include diff --git a/test/comparable/defaults.cpp b/test/comparable/defaults.cpp index 9c9a99963..44f64b35e 100644 --- a/test/comparable/defaults.cpp +++ b/test/comparable/defaults.cpp @@ -4,7 +4,7 @@ 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 +#include #include diff --git a/test/comparable/equal.cpp b/test/comparable/equal.cpp index c34f40400..4fdf8fc1d 100644 --- a/test/comparable/equal.cpp +++ b/test/comparable/equal.cpp @@ -4,7 +4,8 @@ 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 +#include +#include #include #include diff --git a/test/comparable/laws.cpp b/test/comparable/laws.cpp index c6f604704..6acdd8af9 100644 --- a/test/comparable/laws.cpp +++ b/test/comparable/laws.cpp @@ -4,7 +4,9 @@ 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 +#include +#include +#include #include #include diff --git a/test/comparable/not_equal.cpp b/test/comparable/not_equal.cpp index 0dd2fd956..6ffa88ef5 100644 --- a/test/comparable/not_equal.cpp +++ b/test/comparable/not_equal.cpp @@ -4,7 +4,8 @@ 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 +#include +#include #include #include diff --git a/test/lazy/comparable.hpp b/test/lazy/comparable.hpp index 8526c82be..30d702b97 100644 --- a/test/lazy/comparable.hpp +++ b/test/lazy/comparable.hpp @@ -7,7 +7,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_TEST_LAZY_COMPARABLE_HPP #define BOOST_HANA_TEST_LAZY_COMPARABLE_HPP -#include +#include #include diff --git a/test/list/typeclass/minimal.hpp b/test/list/typeclass/minimal.hpp index 1e55b76ae..8be4dcd9d 100644 --- a/test/list/typeclass/minimal.hpp +++ b/test/list/typeclass/minimal.hpp @@ -7,7 +7,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_HANA_TEST_LIST_TYPECLASS_MINIMAL_HPP #define BOOST_HANA_TEST_LIST_TYPECLASS_MINIMAL_HPP -#include +#include #include #include #include diff --git a/test/list/typeclass/sort_by.cpp b/test/list/typeclass/sort_by.cpp index 966b6c231..f81298d2b 100644 --- a/test/list/typeclass/sort_by.cpp +++ b/test/list/typeclass/sort_by.cpp @@ -6,7 +6,7 @@ Distributed under the Boost Software License, Version 1.0. #include -#include +#include #include #include #include diff --git a/test/sandbox/better_laws.cpp b/test/sandbox/better_laws.cpp index dc01bf778..5244b21dc 100644 --- a/test/sandbox/better_laws.cpp +++ b/test/sandbox/better_laws.cpp @@ -4,7 +4,7 @@ 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 +#include #include #include #include diff --git a/test/sandbox/function.cpp b/test/sandbox/function.cpp index f8b88de9a..1841f7735 100644 --- a/test/sandbox/function.cpp +++ b/test/sandbox/function.cpp @@ -4,7 +4,7 @@ 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 +#include #include #include #include diff --git a/test/sandbox/matrix.cpp b/test/sandbox/matrix.cpp index e56961ff7..3330dcf5c 100644 --- a/test/sandbox/matrix.cpp +++ b/test/sandbox/matrix.cpp @@ -4,7 +4,7 @@ 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 +#include #include #include #include