Skip to content

Commit

Permalink
[WIP] Rename the user-defined literal from _s to _dyno
Browse files Browse the repository at this point in the history
_s is overly general, which is problematic since the only way to use the
literal is to bring it into scope with `using namespace dyno::literals`,
which pollutes the global namespace. Using _dyno is less problematic since
it is more specific to this library, even though the namespace pollution
problem still remains.
  • Loading branch information
ldionne committed Jan 6, 2018
1 parent 13d419b commit 6ff3f9b
Show file tree
Hide file tree
Showing 61 changed files with 385 additions and 385 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ using namespace dyno::literals;

// Define the interface of something that can be drawn
struct Drawable : decltype(dyno::requires(
"draw"_s = dyno::method<void (std::ostream&) const>
"draw"_dyno = dyno::method<void (std::ostream&) const>
)) { };

// Define how concrete types can fulfill that interface
template <typename T>
auto const dyno::default_concept_map<Drawable, T> = dyno::make_concept_map(
"draw"_s = [](T const& self, std::ostream& out) { self.draw(out); }
"draw"_dyno = [](T const& self, std::ostream& out) { self.draw(out); }
);

// Define an object that can hold anything that can be drawn.
Expand All @@ -42,7 +42,7 @@ struct drawable {
drawable(T x) : poly_{x} { }

void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out); }
{ poly_.virtual_("draw"_dyno)(out); }

private:
dyno::poly<Drawable> poly_;
Expand Down Expand Up @@ -237,7 +237,7 @@ let's define an interface `Drawable` that describes types that can be drawn:
using namespace dyno::literals;
struct Drawable : decltype(dyno::requires(
"draw"_s = dyno::method<void (std::ostream&) const>
"draw"_dyno = dyno::method<void (std::ostream&) const>
)) { };
```

Expand Down Expand Up @@ -273,7 +273,7 @@ struct Square { /* ... */ };

template <>
auto const dyno::concept_map<Drawable, Square> = dyno::make_concept_map(
"draw"_s = [](Square const& square, std::ostream& out) {
"draw"_dyno = [](Square const& square, std::ostream& out) {
out << "square" << std::endl;
}
);
Expand Down Expand Up @@ -319,7 +319,7 @@ struct drawable {
drawable(T x) : poly_{x} { }
void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out); }
{ poly_.virtual_("draw"_dyno)(out); }
private:
dyno::poly<Drawable> poly_;
Expand Down Expand Up @@ -356,7 +356,7 @@ of the `draw` method:
```c++
void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out); }
{ poly_.virtual_("draw"_dyno)(out); }
```

What happens here is that when `.draw` is called on our `drawable` object,
Expand Down Expand Up @@ -414,7 +414,7 @@ struct drawable {
drawable(T x) : poly_{x} { }

void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out); }
{ poly_.virtual_("draw"_dyno)(out); }

private:
dyno::poly<Drawable, dyno::sbo_storage<16>> poly_;
Expand Down Expand Up @@ -465,7 +465,7 @@ struct drawable {
drawable(T x) : poly_{x} { }
void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out); }
{ poly_.virtual_("draw"_dyno)(out); }
private:
using Storage = dyno::sbo_storage<16>; // storage policy
Expand All @@ -490,12 +490,12 @@ struct drawable {
drawable(T x) : poly_{x} { }

void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out); }
{ poly_.virtual_("draw"_dyno)(out); }

private:
using Storage = dyno::sbo_storage<16>;
using VTable = dyno::vtable<
dyno::local<dyno::only<decltype("draw"_s)>>,
dyno::local<dyno::only<decltype("draw"_dyno)>>,
dyno::remote<dyno::everything_else>
>;
dyno::poly<Drawable, Storage, VTable> poly_;
Expand Down Expand Up @@ -523,7 +523,7 @@ For this, one can use `dyno::default_concept_map`:
```c++
template <typename T>
auto const dyno::default_concept_map<Drawable, T> = dyno::make_concept_map(
"draw"_s = [](auto const& self, std::ostream& out) { self.draw(out); }
"draw"_dyno = [](auto const& self, std::ostream& out) { self.draw(out); }
);
```

Expand All @@ -549,7 +549,7 @@ default one:
```c++
template <>
auto dyno::concept_map<Drawable, Circle> = dyno::make_concept_map(
"draw"_s = [](Circle const& circle, std::ostream& out) {
"draw"_dyno = [](Circle const& circle, std::ostream& out) {
out << "triangle" << std::endl;
}
);
Expand All @@ -569,7 +569,7 @@ template <typename T>
auto const dyno::concept_map<Drawable, std::vector<T>, std::void_t<decltype(
std::cout << std::declval<T>()
)>> = dyno::make_concept_map(
"draw"_s = [](std::vector<T> const& v, std::ostream& out) {
"draw"_dyno = [](std::vector<T> const& v, std::ostream& out) {
for (auto const& x : v)
out << x << ' ';
}
Expand All @@ -591,7 +591,7 @@ the concept using `dyno::function` instead of `dyno::method`, and use the
```c++
// Define the interface of something that can be drawn
struct Drawable : decltype(dyno::requires(
"draw"_s = dyno::function<void (dyno::T const&, std::ostream&)>
"draw"_dyno = dyno::function<void (dyno::T const&, std::ostream&)>
)) { };
```

Expand All @@ -601,7 +601,7 @@ first parameter:

```c++
struct Drawable : decltype(dyno::requires(
"draw"_s = dyno::function<void (std::ostream&, dyno::T const&)>
"draw"_dyno = dyno::function<void (std::ostream&, dyno::T const&)>
)) { };
```
Expand All @@ -613,7 +613,7 @@ implementation match that of the function declared in the concept:
// Define how concrete types can fulfill that interface
template <typename T>
auto const dyno::default_concept_map<Drawable, T> = dyno::make_concept_map(
"draw"_s = [](std::ostream& out, T const& self) { self.draw(out); }
"draw"_dyno = [](std::ostream& out, T const& self) { self.draw(out); }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ matches the concept definition
);
```
Expand All @@ -630,7 +630,7 @@ struct drawable {
drawable(T x) : poly_{x} { }

void draw(std::ostream& out) const
{ poly_.virtual_("draw"_s)(out, poly_); }
{ poly_.virtual_("draw"_dyno)(out, poly_); }
// ^^^^^ passing the poly explicitly

private:
Expand Down
24 changes: 12 additions & 12 deletions benchmark/any_iterator/dyno_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace dyno_generic {
template <typename Reference>
struct Iterator : decltype(dyno::requires(
dyno::MoveConstructible{},
"increment"_s = dyno::function<void (dyno::T&)>,
"dereference"_s = dyno::function<Reference (dyno::T&)>,
"equal"_s = dyno::function<bool (dyno::T const&, dyno::T const&)>
"increment"_dyno = dyno::function<void (dyno::T&)>,
"dereference"_dyno = dyno::function<Reference (dyno::T&)>,
"equal"_dyno = dyno::function<bool (dyno::T const&, dyno::T const&)>
)) { };

template <typename Value, typename StoragePolicy, typename VTablePolicy, typename Reference = Value&>
Expand All @@ -27,9 +27,9 @@ namespace dyno_generic {
template <typename It>
explicit any_iterator(It it)
: poly_{std::move(it), dyno::make_concept_map(
"increment"_s = [](It& self) { ++self; },
"dereference"_s = [](It& self) -> decltype(auto) { return *self; },
"equal"_s = [](It const& a, It const& b) -> bool { return a == b; }
"increment"_dyno = [](It& self) { ++self; },
"dereference"_dyno = [](It& self) -> decltype(auto) { return *self; },
"equal"_dyno = [](It const& a, It const& b) -> bool { return a == b; }
)}
{ }

Expand All @@ -38,16 +38,16 @@ namespace dyno_generic {
{ }

any_iterator& operator++() {
poly_.virtual_("increment"_s)(poly_);
poly_.virtual_("increment"_dyno)(poly_);
return *this;
}

reference operator*() {
return poly_.virtual_("dereference"_s)(poly_);
return poly_.virtual_("dereference"_dyno)(poly_);
}

friend bool operator==(any_iterator const& a, any_iterator const& b) {
return a.poly_.virtual_("equal"_s)(a.poly_, b.poly_);
return a.poly_.virtual_("equal"_dyno)(a.poly_, b.poly_);
}

private:
Expand All @@ -66,9 +66,9 @@ namespace dyno_generic {
int,
dyno::local_storage<16>,
dyno::vtable<
dyno::local<dyno::only<decltype("increment"_s),
decltype("dereference"_s),
decltype("equal"_s)>>,
dyno::local<dyno::only<decltype("increment"_dyno),
decltype("dereference"_dyno),
decltype("equal"_dyno)>>,
dyno::remote<dyno::everything_else>
>
>;
Expand Down
30 changes: 15 additions & 15 deletions benchmark/n_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ namespace { namespace dyno_remote {
using namespace dyno::literals;

struct Concept : decltype(dyno::requires(
"f1"_s = dyno::function<void (dyno::T&)>,
"f2"_s = dyno::function<void (dyno::T&)>,
"f3"_s = dyno::function<void (dyno::T&)>,
"f4"_s = dyno::function<void (dyno::T&)>,
"f5"_s = dyno::function<void (dyno::T&)>
"f1"_dyno = dyno::function<void (dyno::T&)>,
"f2"_dyno = dyno::function<void (dyno::T&)>,
"f3"_dyno = dyno::function<void (dyno::T&)>,
"f4"_dyno = dyno::function<void (dyno::T&)>,
"f5"_dyno = dyno::function<void (dyno::T&)>
)) { };

template <typename Policy>
Expand All @@ -193,21 +193,21 @@ namespace { namespace dyno_remote {
explicit any_template(T t)
: vtable_{
dyno::complete_concept_map<Concept, T>(dyno::make_concept_map(
"f1"_s = [](T& self) { ++self; },
"f2"_s = [](T& self) { --self; },
"f3"_s = [](T& self) { ++self; },
"f4"_s = [](T& self) { --self; },
"f5"_s = [](T& self) { ++self; }
"f1"_dyno = [](T& self) { ++self; },
"f2"_dyno = [](T& self) { --self; },
"f3"_dyno = [](T& self) { ++self; },
"f4"_dyno = [](T& self) { --self; },
"f5"_dyno = [](T& self) { ++self; }
))
}
, self_{new T(t)}
{ }

any_template& f1() { vtable_["f1"_s](self_); return *this; }
any_template& f2() { vtable_["f2"_s](self_); return *this; }
any_template& f3() { vtable_["f3"_s](self_); return *this; }
any_template& f4() { vtable_["f4"_s](self_); return *this; }
any_template& f5() { vtable_["f5"_s](self_); return *this; }
any_template& f1() { vtable_["f1"_dyno](self_); return *this; }
any_template& f2() { vtable_["f2"_dyno](self_); return *this; }
any_template& f3() { vtable_["f3"_dyno](self_); return *this; }
any_template& f4() { vtable_["f4"_dyno](self_); return *this; }
any_template& f5() { vtable_["f5"_dyno](self_); return *this; }

private:
using VTable = typename dyno::vtable<Policy>::template apply<Concept>;
Expand Down
18 changes: 9 additions & 9 deletions benchmark/storage/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ struct Concept : decltype(dyno::requires(
dyno::Swappable{},
dyno::Destructible{},
dyno::Storable{},
"f1"_s = dyno::function<void(dyno::T&)>,
"f2"_s = dyno::function<void(dyno::T&)>,
"f3"_s = dyno::function<void(dyno::T&)>
"f1"_dyno = dyno::function<void(dyno::T&)>,
"f2"_dyno = dyno::function<void(dyno::T&)>,
"f3"_dyno = dyno::function<void(dyno::T&)>
)) { };

template <typename T>
auto const dyno::default_concept_map<Concept, T> = dyno::make_concept_map(
"f1"_s = [](T& self) { benchmark::DoNotOptimize(self); },
"f2"_s = [](T& self) { benchmark::DoNotOptimize(self); },
"f3"_s = [](T& self) { benchmark::DoNotOptimize(self); }
"f1"_dyno = [](T& self) { benchmark::DoNotOptimize(self); },
"f2"_dyno = [](T& self) { benchmark::DoNotOptimize(self); },
"f3"_dyno = [](T& self) { benchmark::DoNotOptimize(self); }
);

template <typename StoragePolicy>
Expand All @@ -37,9 +37,9 @@ struct model {

void swap(model& other) { poly_.swap(other.poly_); }

void f1() { poly_.virtual_("f1"_s)(poly_); }
void f2() { poly_.virtual_("f2"_s)(poly_); }
void f3() { poly_.virtual_("f3"_s)(poly_); }
void f1() { poly_.virtual_("f1"_dyno)(poly_); }
void f2() { poly_.virtual_("f2"_dyno)(poly_); }
void f3() { poly_.virtual_("f3"_dyno)(poly_); }

private:
dyno::poly<Concept, StoragePolicy> poly_;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/vtable/dispatch.2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ using inline_only = dyno::vtable<
static constexpr int N = 100;
BENCHMARK_TEMPLATE(BM_dispatch2, inheritance_tag)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_s), decltype("f2"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_dyno)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_dyno), decltype("f2"_dyno)>)->Arg(N);
BENCHMARK_MAIN();
6 changes: 3 additions & 3 deletions benchmark/vtable/dispatch.3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using inline_only = dyno::vtable<
static constexpr int N = 100;
BENCHMARK_TEMPLATE(BM_dispatch3, inheritance_tag)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_s), decltype("f2"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_s), decltype("f2"_s), decltype("f3"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_dyno)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_dyno), decltype("f2"_dyno)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_dyno), decltype("f2"_dyno), decltype("f3"_dyno)>)->Arg(N);
BENCHMARK_MAIN();
8 changes: 4 additions & 4 deletions benchmark/vtable/dispatch.4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ using inline_only = dyno::vtable<
static constexpr int N = 100;
BENCHMARK_TEMPLATE(BM_dispatch4, inheritance_tag)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s), decltype("f2"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s), decltype("f2"_s), decltype("f3"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s), decltype("f2"_s), decltype("f3"_s), decltype("f4"_s)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno), decltype("f2"_dyno)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno), decltype("f2"_dyno), decltype("f3"_dyno)>)->Arg(N);
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno), decltype("f2"_dyno), decltype("f3"_dyno), decltype("f4"_dyno)>)->Arg(N);
BENCHMARK_MAIN();
24 changes: 12 additions & 12 deletions benchmark/vtable/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ struct Concept : decltype(dyno::requires(
dyno::Swappable{},
dyno::Destructible{},
dyno::Storable{},
"f1"_s = dyno::function<void(dyno::T&)>,
"f2"_s = dyno::function<void(dyno::T&)>,
"f3"_s = dyno::function<void(dyno::T&)>,
"f4"_s = dyno::function<void(dyno::T&)>
"f1"_dyno = dyno::function<void(dyno::T&)>,
"f2"_dyno = dyno::function<void(dyno::T&)>,
"f3"_dyno = dyno::function<void(dyno::T&)>,
"f4"_dyno = dyno::function<void(dyno::T&)>
)) { };

template <typename T>
auto const dyno::default_concept_map<Concept, T> = dyno::make_concept_map(
"f1"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
"f2"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
"f3"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
"f4"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); }
"f1"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
"f2"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
"f3"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
"f4"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); }
);

template <typename VTablePolicy>
Expand All @@ -38,10 +38,10 @@ struct model {
: poly_{std::move(t)}
{ }

void f1() { poly_.virtual_("f1"_s)(poly_); }
void f2() { poly_.virtual_("f2"_s)(poly_); }
void f3() { poly_.virtual_("f3"_s)(poly_); }
void f4() { poly_.virtual_("f4"_s)(poly_); }
void f1() { poly_.virtual_("f1"_dyno)(poly_); }
void f2() { poly_.virtual_("f2"_dyno)(poly_); }
void f3() { poly_.virtual_("f3"_dyno)(poly_); }
void f4() { poly_.virtual_("f4"_dyno)(poly_); }

private:
dyno::poly<Concept, dyno::local_storage<8>, VTablePolicy> poly_;
Expand Down
Loading

0 comments on commit 6ff3f9b

Please sign in to comment.