Skip to content

Commit

Permalink
Add member function test for struct concept
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebionne committed Jun 11, 2019
1 parent daa802d commit 22dfd8a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/concept/struct/macro.adapt_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ namespace ns {
struct MemberArray {
int array[10];
};
struct MemberFunction {
int memfun(int x) { return x + 1; }
};
}

BOOST_HANA_ADAPT_STRUCT(ns::Data0);
BOOST_HANA_ADAPT_STRUCT(ns::Data1, member1);
BOOST_HANA_ADAPT_STRUCT(ns::Data2, member1, member2);
BOOST_HANA_ADAPT_STRUCT(ns::Data3, member1, member2, member3);
BOOST_HANA_ADAPT_STRUCT(ns::MemberArray, array);
BOOST_HANA_ADAPT_STRUCT(ns::MemberFunction, memfun);

static_assert(hana::Struct<ns::Data0>::value, "");
static_assert(hana::Struct<ns::Data1>::value, "");
static_assert(hana::Struct<ns::Data2>::value, "");
static_assert(hana::Struct<ns::Data3>::value, "");
static_assert(hana::Struct<ns::MemberArray>::value, "");
static_assert(hana::Struct<ns::MemberFunction>::value, "");

int main() {
BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data1{}, BOOST_HANA_STRING("member1")));
Expand All @@ -55,4 +60,9 @@ int main() {
BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member3")));

BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::MemberArray{}, BOOST_HANA_STRING("array")));

BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::MemberFunction{}, BOOST_HANA_STRING("memfun")));

constexpr auto accessors = hana::accessors<ns::MemberFunction>();
BOOST_HANA_RUNTIME_CHECK(hana::second(accessors[hana::size_c<0>])(ns::MemberFunction{})(1) == 2);
}

0 comments on commit 22dfd8a

Please sign in to comment.