Skip to content

Commit

Permalink
[vtable] Improve unit tests for cv-qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ldionne committed Sep 13, 2017
1 parent 83e1267 commit 0ebcf09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/dyno/detail/is_placeholder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace dyno { namespace detail {

// Metafunction returning whether a type is a possibly cv/ref-qualified
// Metafunction returning whether a type is a possibly const/ref-qualified
// placeholder, or a pointer to one.
template <typename T>
struct is_placeholder : std::false_type { };
Expand Down
28 changes: 22 additions & 6 deletions test/vtable.cv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,39 @@ using namespace dyno::literals;
//

struct Concept : decltype(dyno::requires(
"f"_s = dyno::function<int (dyno::T&)>,
"g"_s = dyno::function<int (dyno::T*)>
"f1"_s = dyno::function<int (dyno::T&)>,
"f2"_s = dyno::function<int (dyno::T*)>,
"f3"_s = dyno::function<int (dyno::T&)>,
"f4"_s = dyno::function<int (dyno::T*)>,
"f5"_s = dyno::function<int (dyno::T&)>,
"f6"_s = dyno::function<int (dyno::T*)>,
"f7"_s = dyno::function<int (dyno::T&, int&)>
)) { };

struct Foo { };

template <>
auto const dyno::concept_map<Concept, Foo> = dyno::make_concept_map(
"f"_s = [](Foo const&) { return 111; },
"g"_s = [](Foo const*) { return 222; }
"f1"_s = [](Foo const&) { return 111; },
"f2"_s = [](Foo const*) { return 222; },
"f3"_s = [](Foo volatile&) { return 333; },
"f4"_s = [](Foo volatile*) { return 444; },
"f5"_s = [](Foo const volatile&) { return 555; },
"f6"_s = [](Foo const volatile*) { return 666; },
"f7"_s = [](Foo&, int const&) { return 777; }
);

int main() {
auto complete = dyno::complete_concept_map<Concept, Foo>(dyno::concept_map<Concept, Foo>);
dyno::vtable<dyno::local<dyno::everything>>::apply<Concept> vtable{complete};

Foo foo;
DYNO_CHECK(vtable["f"_s](&foo) == 111); // erased as a void*
DYNO_CHECK(vtable["g"_s](&foo) == 222); // erased as a void*
int i = 0;
DYNO_CHECK(vtable["f1"_s](&foo) == 111); // erased as a void*
DYNO_CHECK(vtable["f2"_s](&foo) == 222); // erased as a void*
DYNO_CHECK(vtable["f3"_s](&foo) == 333); // erased as a void*
DYNO_CHECK(vtable["f4"_s](&foo) == 444); // erased as a void*
DYNO_CHECK(vtable["f5"_s](&foo) == 555); // erased as a void*
DYNO_CHECK(vtable["f6"_s](&foo) == 666); // erased as a void*
DYNO_CHECK(vtable["f7"_s](&foo, i) == 777);
}

0 comments on commit 0ebcf09

Please sign in to comment.