Skip to content

Commit 6d40e29

Browse files
[SetTheoretic] Add SetTheoretic concept
It adds SetTheoretic concept for functions- union, intersection, difference, symmetric_difference. Closes #357
1 parent ff59738 commit 6d40e29

File tree

6 files changed

+114
-9
lines changed

6 files changed

+114
-9
lines changed

Diff for: include/boost/hana/concept.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Distributed under the Boost Software License, Version 1.0.
3131
#include <boost/hana/concept/ring.hpp>
3232
#include <boost/hana/concept/searchable.hpp>
3333
#include <boost/hana/concept/sequence.hpp>
34+
#include <boost/hana/concept/set_theoretic.hpp>
3435
#include <boost/hana/concept/struct.hpp>
3536

3637
#endif // !BOOST_HANA_CONCEPT_HPP

Diff for: include/boost/hana/concept/set_theoretic.hpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*!
2+
@file
3+
Defines `boost::hana::SetTheoretic`.
4+
5+
@copyright Shreyans Doshi 2017
6+
Distributed under the Boost Software License, Version 1.0.
7+
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8+
*/
9+
10+
#ifndef BOOST_HANA_CONCEPT_SET_THEORETIC_HPP
11+
#define BOOST_HANA_CONCEPT_SET_THEORETIC_HPP
12+
13+
#include <boost/hana/fwd/concept/set_theoretic.hpp>
14+
15+
#include <boost/hana/config.hpp>
16+
#include <boost/hana/core/default.hpp>
17+
#include <boost/hana/core/tag_of.hpp>
18+
#include <boost/hana/detail/integral_constant.hpp>
19+
#include <boost/hana/difference.hpp>
20+
#include <boost/hana/intersection.hpp>
21+
#include <boost/hana/symmetric_difference.hpp>
22+
#include <boost/hana/union.hpp>
23+
24+
25+
BOOST_HANA_NAMESPACE_BEGIN
26+
template <typename STh>
27+
struct SetTheoretic
28+
: hana::integral_constant<bool,
29+
!is_default<difference_impl<typename tag_of<STh>::type>>::value &&
30+
!is_default<intersection_impl<typename tag_of<STh>::type>>::value &&
31+
!is_default<union_impl<typename tag_of<STh>::type>>::value
32+
>
33+
{ };
34+
BOOST_HANA_NAMESPACE_END
35+
36+
#endif // !BOOST_HANA_CONCEPT_SET_THEORETIC_HPP

Diff for: include/boost/hana/difference.hpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Distributed under the Boost Software License, Version 1.0.
1212

1313
#include <boost/hana/fwd/difference.hpp>
1414

15+
#include <boost/hana/concept/set_theoretic.hpp>
1516
#include <boost/hana/config.hpp>
1617
#include <boost/hana/core/dispatch.hpp>
1718
#include <boost/hana/erase_key.hpp>
@@ -21,11 +22,21 @@ BOOST_HANA_NAMESPACE_BEGIN
2122
//! @cond
2223
template <typename Xs, typename Ys>
2324
constexpr auto difference_t::operator()(Xs&& xs, Ys&& ys) const {
24-
using S = typename hana::tag_of<Xs>::type;
25-
using Difference = BOOST_HANA_DISPATCH_IF(difference_impl<S>,
26-
true
25+
using TX = typename hana::tag_of<Xs>::type;
26+
using TY = typename hana::tag_of<Ys>::type;
27+
using Difference = BOOST_HANA_DISPATCH_IF(difference_impl<TX>,
28+
hana::SetTheoretic<TX>::value &&
29+
std::is_same<TX, TY>::value
2730
);
2831

32+
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
33+
static_assert(hana::SetTheoretic<TX>::value,
34+
"hana::difference(xs, ys) requires 'xs' to be SetTheoretic");
35+
36+
static_assert(std::is_same<TX, TY>::value,
37+
"hana::difference(xs, ys) requires 'xs' and 'ys' to be of the same type");
38+
#endif
39+
2940
return Difference::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
3041
}
3142
//! @endcond

Diff for: include/boost/hana/fwd/concept/set_theoretic.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
@file
3+
Forward declares `boost::hana::SetTheoretic`.
4+
5+
@copyright Shreyans Doshi 2017
6+
Distributed under the Boost Software License, Version 1.0.
7+
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8+
*/
9+
10+
#ifndef BOOST_HANA_FWD_CONCEPT_SET_THEORETIC_HPP
11+
#define BOOST_HANA_FWD_CONCEPT_SET_THEORETIC_HPP
12+
13+
#include <boost/hana/config.hpp>
14+
15+
16+
BOOST_HANA_NAMESPACE_BEGIN
17+
//! @ingroup group-concepts
18+
//! @defgroup group-SetTheoretic SetTheoretic
19+
//! The `SetTheoretic` concept represents data structures supporting
20+
//! algebra of sets.
21+
//!
22+
//! Minimal complete definition
23+
//! ---------------------------
24+
//! `union_`, `intersection`, `difference` and `symmetric_difference`
25+
//!
26+
//! Concrete models
27+
//! ---------------
28+
//! `hana::set`, `hana::map`
29+
//!
30+
//!
31+
template <typename STh>
32+
struct SetTheoretic;
33+
BOOST_HANA_NAMESPACE_END
34+
35+
#endif // !BOOST_HANA_FWD_CONCEPT_SET_THEORETIC_HPP

Diff for: include/boost/hana/intersection.hpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Distributed under the Boost Software License, Version 1.0.
1212

1313
#include <boost/hana/fwd/intersection.hpp>
1414

15+
#include <boost/hana/concept/set_theoretic.hpp>
1516
#include <boost/hana/config.hpp>
1617
#include <boost/hana/core/dispatch.hpp>
1718

@@ -20,10 +21,20 @@ BOOST_HANA_NAMESPACE_BEGIN
2021
//! @cond
2122
template <typename Xs, typename Ys>
2223
constexpr auto intersection_t::operator()(Xs&& xs, Ys&& ys) const {
23-
using S = typename hana::tag_of<Xs>::type;
24-
using Intersection = BOOST_HANA_DISPATCH_IF(intersection_impl<S>,
25-
true
24+
using TX = typename hana::tag_of<Xs>::type;
25+
using TY = typename hana::tag_of<Ys>::type;
26+
using Intersection = BOOST_HANA_DISPATCH_IF(intersection_impl<TX>,
27+
hana::SetTheoretic<TX>::value &&
28+
std::is_same<TX, TY>::value
2629
);
30+
31+
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
32+
static_assert(hana::SetTheoretic<TX>::value,
33+
"hana::intersection(xs, ys) requires 'xs' to be SetTheoretic");
34+
35+
static_assert(std::is_same<TX, TY>::value,
36+
"hana::intersection(xs, ys) requires 'xs' and 'ys' to be of the same type");
37+
#endif
2738

2839
return Intersection::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
2940
}

Diff for: include/boost/hana/union.hpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Distributed under the Boost Software License, Version 1.0.
1212

1313
#include <boost/hana/fwd/union.hpp>
1414

15+
#include <boost/hana/concept/set_theoretic.hpp>
1516
#include <boost/hana/config.hpp>
1617
#include <boost/hana/core/dispatch.hpp>
1718

@@ -20,11 +21,21 @@ BOOST_HANA_NAMESPACE_BEGIN
2021
//! @cond
2122
template <typename Xs, typename Ys>
2223
constexpr auto union_t::operator()(Xs&& xs, Ys&& ys) const {
23-
using S = typename hana::tag_of<Xs>::type;
24-
using Union = BOOST_HANA_DISPATCH_IF(union_impl<S>,
25-
true
24+
using TX = typename hana::tag_of<Xs>::type;
25+
using TY = typename hana::tag_of<Ys>::type;
26+
using Union = BOOST_HANA_DISPATCH_IF(union_impl<TX>,
27+
hana::SetTheoretic<TX>::value &&
28+
std::is_same<TX, TY>::value
2629
);
2730

31+
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
32+
static_assert(hana::SetTheoretic<TX>::value,
33+
"hana::union_(xs, ys) requires 'xs' to be SetTheoretic");
34+
35+
static_assert(std::is_same<TX, TY>::value,
36+
"hana::union_(xs, ys) requires 'xs' and 'ys' to be of the same type");
37+
#endif
38+
2839
return Union::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
2940
}
3041
//! @endcond

0 commit comments

Comments
 (0)