Skip to content

Commit 6ff3f9b

Browse files
committed
[WIP] Rename the user-defined literal from _s to _dyno
_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.
1 parent 13d419b commit 6ff3f9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+385
-385
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ using namespace dyno::literals;
2727

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

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

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

4444
void draw(std::ostream& out) const
45-
{ poly_.virtual_("draw"_s)(out); }
45+
{ poly_.virtual_("draw"_dyno)(out); }
4646

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

@@ -273,7 +273,7 @@ struct Square { /* ... */ };
273273

274274
template <>
275275
auto const dyno::concept_map<Drawable, Square> = dyno::make_concept_map(
276-
"draw"_s = [](Square const& square, std::ostream& out) {
276+
"draw"_dyno = [](Square const& square, std::ostream& out) {
277277
out << "square" << std::endl;
278278
}
279279
);
@@ -319,7 +319,7 @@ struct drawable {
319319
drawable(T x) : poly_{x} { }
320320
321321
void draw(std::ostream& out) const
322-
{ poly_.virtual_("draw"_s)(out); }
322+
{ poly_.virtual_("draw"_dyno)(out); }
323323
324324
private:
325325
dyno::poly<Drawable> poly_;
@@ -356,7 +356,7 @@ of the `draw` method:
356356
357357
```c++
358358
void draw(std::ostream& out) const
359-
{ poly_.virtual_("draw"_s)(out); }
359+
{ poly_.virtual_("draw"_dyno)(out); }
360360
```
361361

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

416416
void draw(std::ostream& out) const
417-
{ poly_.virtual_("draw"_s)(out); }
417+
{ poly_.virtual_("draw"_dyno)(out); }
418418

419419
private:
420420
dyno::poly<Drawable, dyno::sbo_storage<16>> poly_;
@@ -465,7 +465,7 @@ struct drawable {
465465
drawable(T x) : poly_{x} { }
466466
467467
void draw(std::ostream& out) const
468-
{ poly_.virtual_("draw"_s)(out); }
468+
{ poly_.virtual_("draw"_dyno)(out); }
469469
470470
private:
471471
using Storage = dyno::sbo_storage<16>; // storage policy
@@ -490,12 +490,12 @@ struct drawable {
490490
drawable(T x) : poly_{x} { }
491491

492492
void draw(std::ostream& out) const
493-
{ poly_.virtual_("draw"_s)(out); }
493+
{ poly_.virtual_("draw"_dyno)(out); }
494494

495495
private:
496496
using Storage = dyno::sbo_storage<16>;
497497
using VTable = dyno::vtable<
498-
dyno::local<dyno::only<decltype("draw"_s)>>,
498+
dyno::local<dyno::only<decltype("draw"_dyno)>>,
499499
dyno::remote<dyno::everything_else>
500500
>;
501501
dyno::poly<Drawable, Storage, VTable> poly_;
@@ -523,7 +523,7 @@ For this, one can use `dyno::default_concept_map`:
523523
```c++
524524
template <typename T>
525525
auto const dyno::default_concept_map<Drawable, T> = dyno::make_concept_map(
526-
"draw"_s = [](auto const& self, std::ostream& out) { self.draw(out); }
526+
"draw"_dyno = [](auto const& self, std::ostream& out) { self.draw(out); }
527527
);
528528
```
529529

@@ -549,7 +549,7 @@ default one:
549549
```c++
550550
template <>
551551
auto dyno::concept_map<Drawable, Circle> = dyno::make_concept_map(
552-
"draw"_s = [](Circle const& circle, std::ostream& out) {
552+
"draw"_dyno = [](Circle const& circle, std::ostream& out) {
553553
out << "triangle" << std::endl;
554554
}
555555
);
@@ -569,7 +569,7 @@ template <typename T>
569569
auto const dyno::concept_map<Drawable, std::vector<T>, std::void_t<decltype(
570570
std::cout << std::declval<T>()
571571
)>> = dyno::make_concept_map(
572-
"draw"_s = [](std::vector<T> const& v, std::ostream& out) {
572+
"draw"_dyno = [](std::vector<T> const& v, std::ostream& out) {
573573
for (auto const& x : v)
574574
out << x << ' ';
575575
}
@@ -591,7 +591,7 @@ the concept using `dyno::function` instead of `dyno::method`, and use the
591591
```c++
592592
// Define the interface of something that can be drawn
593593
struct Drawable : decltype(dyno::requires(
594-
"draw"_s = dyno::function<void (dyno::T const&, std::ostream&)>
594+
"draw"_dyno = dyno::function<void (dyno::T const&, std::ostream&)>
595595
)) { };
596596
```
597597

@@ -601,7 +601,7 @@ first parameter:
601601

602602
```c++
603603
struct Drawable : decltype(dyno::requires(
604-
"draw"_s = dyno::function<void (std::ostream&, dyno::T const&)>
604+
"draw"_dyno = dyno::function<void (std::ostream&, dyno::T const&)>
605605
)) { };
606606
```
607607
@@ -613,7 +613,7 @@ implementation match that of the function declared in the concept:
613613
// Define how concrete types can fulfill that interface
614614
template <typename T>
615615
auto const dyno::default_concept_map<Drawable, T> = dyno::make_concept_map(
616-
"draw"_s = [](std::ostream& out, T const& self) { self.draw(out); }
616+
"draw"_dyno = [](std::ostream& out, T const& self) { self.draw(out); }
617617
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ matches the concept definition
618618
);
619619
```
@@ -630,7 +630,7 @@ struct drawable {
630630
drawable(T x) : poly_{x} { }
631631

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

636636
private:

benchmark/any_iterator/dyno_generic.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace dyno_generic {
1414
template <typename Reference>
1515
struct Iterator : decltype(dyno::requires(
1616
dyno::MoveConstructible{},
17-
"increment"_s = dyno::function<void (dyno::T&)>,
18-
"dereference"_s = dyno::function<Reference (dyno::T&)>,
19-
"equal"_s = dyno::function<bool (dyno::T const&, dyno::T const&)>
17+
"increment"_dyno = dyno::function<void (dyno::T&)>,
18+
"dereference"_dyno = dyno::function<Reference (dyno::T&)>,
19+
"equal"_dyno = dyno::function<bool (dyno::T const&, dyno::T const&)>
2020
)) { };
2121

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

@@ -38,16 +38,16 @@ namespace dyno_generic {
3838
{ }
3939

4040
any_iterator& operator++() {
41-
poly_.virtual_("increment"_s)(poly_);
41+
poly_.virtual_("increment"_dyno)(poly_);
4242
return *this;
4343
}
4444

4545
reference operator*() {
46-
return poly_.virtual_("dereference"_s)(poly_);
46+
return poly_.virtual_("dereference"_dyno)(poly_);
4747
}
4848

4949
friend bool operator==(any_iterator const& a, any_iterator const& b) {
50-
return a.poly_.virtual_("equal"_s)(a.poly_, b.poly_);
50+
return a.poly_.virtual_("equal"_dyno)(a.poly_, b.poly_);
5151
}
5252

5353
private:
@@ -66,9 +66,9 @@ namespace dyno_generic {
6666
int,
6767
dyno::local_storage<16>,
6868
dyno::vtable<
69-
dyno::local<dyno::only<decltype("increment"_s),
70-
decltype("dereference"_s),
71-
decltype("equal"_s)>>,
69+
dyno::local<dyno::only<decltype("increment"_dyno),
70+
decltype("dereference"_dyno),
71+
decltype("equal"_dyno)>>,
7272
dyno::remote<dyno::everything_else>
7373
>
7474
>;

benchmark/n_functions.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ namespace { namespace dyno_remote {
180180
using namespace dyno::literals;
181181

182182
struct Concept : decltype(dyno::requires(
183-
"f1"_s = dyno::function<void (dyno::T&)>,
184-
"f2"_s = dyno::function<void (dyno::T&)>,
185-
"f3"_s = dyno::function<void (dyno::T&)>,
186-
"f4"_s = dyno::function<void (dyno::T&)>,
187-
"f5"_s = dyno::function<void (dyno::T&)>
183+
"f1"_dyno = dyno::function<void (dyno::T&)>,
184+
"f2"_dyno = dyno::function<void (dyno::T&)>,
185+
"f3"_dyno = dyno::function<void (dyno::T&)>,
186+
"f4"_dyno = dyno::function<void (dyno::T&)>,
187+
"f5"_dyno = dyno::function<void (dyno::T&)>
188188
)) { };
189189

190190
template <typename Policy>
@@ -193,21 +193,21 @@ namespace { namespace dyno_remote {
193193
explicit any_template(T t)
194194
: vtable_{
195195
dyno::complete_concept_map<Concept, T>(dyno::make_concept_map(
196-
"f1"_s = [](T& self) { ++self; },
197-
"f2"_s = [](T& self) { --self; },
198-
"f3"_s = [](T& self) { ++self; },
199-
"f4"_s = [](T& self) { --self; },
200-
"f5"_s = [](T& self) { ++self; }
196+
"f1"_dyno = [](T& self) { ++self; },
197+
"f2"_dyno = [](T& self) { --self; },
198+
"f3"_dyno = [](T& self) { ++self; },
199+
"f4"_dyno = [](T& self) { --self; },
200+
"f5"_dyno = [](T& self) { ++self; }
201201
))
202202
}
203203
, self_{new T(t)}
204204
{ }
205205

206-
any_template& f1() { vtable_["f1"_s](self_); return *this; }
207-
any_template& f2() { vtable_["f2"_s](self_); return *this; }
208-
any_template& f3() { vtable_["f3"_s](self_); return *this; }
209-
any_template& f4() { vtable_["f4"_s](self_); return *this; }
210-
any_template& f5() { vtable_["f5"_s](self_); return *this; }
206+
any_template& f1() { vtable_["f1"_dyno](self_); return *this; }
207+
any_template& f2() { vtable_["f2"_dyno](self_); return *this; }
208+
any_template& f3() { vtable_["f3"_dyno](self_); return *this; }
209+
any_template& f4() { vtable_["f4"_dyno](self_); return *this; }
210+
any_template& f5() { vtable_["f5"_dyno](self_); return *this; }
211211

212212
private:
213213
using VTable = typename dyno::vtable<Policy>::template apply<Concept>;

benchmark/storage/model.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ struct Concept : decltype(dyno::requires(
1616
dyno::Swappable{},
1717
dyno::Destructible{},
1818
dyno::Storable{},
19-
"f1"_s = dyno::function<void(dyno::T&)>,
20-
"f2"_s = dyno::function<void(dyno::T&)>,
21-
"f3"_s = dyno::function<void(dyno::T&)>
19+
"f1"_dyno = dyno::function<void(dyno::T&)>,
20+
"f2"_dyno = dyno::function<void(dyno::T&)>,
21+
"f3"_dyno = dyno::function<void(dyno::T&)>
2222
)) { };
2323

2424
template <typename T>
2525
auto const dyno::default_concept_map<Concept, T> = dyno::make_concept_map(
26-
"f1"_s = [](T& self) { benchmark::DoNotOptimize(self); },
27-
"f2"_s = [](T& self) { benchmark::DoNotOptimize(self); },
28-
"f3"_s = [](T& self) { benchmark::DoNotOptimize(self); }
26+
"f1"_dyno = [](T& self) { benchmark::DoNotOptimize(self); },
27+
"f2"_dyno = [](T& self) { benchmark::DoNotOptimize(self); },
28+
"f3"_dyno = [](T& self) { benchmark::DoNotOptimize(self); }
2929
);
3030

3131
template <typename StoragePolicy>
@@ -37,9 +37,9 @@ struct model {
3737

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

40-
void f1() { poly_.virtual_("f1"_s)(poly_); }
41-
void f2() { poly_.virtual_("f2"_s)(poly_); }
42-
void f3() { poly_.virtual_("f3"_s)(poly_); }
40+
void f1() { poly_.virtual_("f1"_dyno)(poly_); }
41+
void f2() { poly_.virtual_("f2"_dyno)(poly_); }
42+
void f3() { poly_.virtual_("f3"_dyno)(poly_); }
4343

4444
private:
4545
dyno::poly<Concept, StoragePolicy> poly_;

benchmark/vtable/dispatch.2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ using inline_only = dyno::vtable<
3636
static constexpr int N = 100;
3737
BENCHMARK_TEMPLATE(BM_dispatch2, inheritance_tag)->Arg(N);
3838
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<>)->Arg(N);
39-
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_s)>)->Arg(N);
40-
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_s), decltype("f2"_s)>)->Arg(N);
39+
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_dyno)>)->Arg(N);
40+
BENCHMARK_TEMPLATE(BM_dispatch2, inline_only<decltype("f1"_dyno), decltype("f2"_dyno)>)->Arg(N);
4141
BENCHMARK_MAIN();

benchmark/vtable/dispatch.3.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using inline_only = dyno::vtable<
3737
static constexpr int N = 100;
3838
BENCHMARK_TEMPLATE(BM_dispatch3, inheritance_tag)->Arg(N);
3939
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<>)->Arg(N);
40-
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_s)>)->Arg(N);
41-
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_s), decltype("f2"_s)>)->Arg(N);
42-
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_s), decltype("f2"_s), decltype("f3"_s)>)->Arg(N);
40+
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_dyno)>)->Arg(N);
41+
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_dyno), decltype("f2"_dyno)>)->Arg(N);
42+
BENCHMARK_TEMPLATE(BM_dispatch3, inline_only<decltype("f1"_dyno), decltype("f2"_dyno), decltype("f3"_dyno)>)->Arg(N);
4343
BENCHMARK_MAIN();

benchmark/vtable/dispatch.4.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ using inline_only = dyno::vtable<
3838
static constexpr int N = 100;
3939
BENCHMARK_TEMPLATE(BM_dispatch4, inheritance_tag)->Arg(N);
4040
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<>)->Arg(N);
41-
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s)>)->Arg(N);
42-
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s), decltype("f2"_s)>)->Arg(N);
43-
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s), decltype("f2"_s), decltype("f3"_s)>)->Arg(N);
44-
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_s), decltype("f2"_s), decltype("f3"_s), decltype("f4"_s)>)->Arg(N);
41+
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno)>)->Arg(N);
42+
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno), decltype("f2"_dyno)>)->Arg(N);
43+
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno), decltype("f2"_dyno), decltype("f3"_dyno)>)->Arg(N);
44+
BENCHMARK_TEMPLATE(BM_dispatch4, inline_only<decltype("f1"_dyno), decltype("f2"_dyno), decltype("f3"_dyno), decltype("f4"_dyno)>)->Arg(N);
4545
BENCHMARK_MAIN();

benchmark/vtable/model.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ struct Concept : decltype(dyno::requires(
1717
dyno::Swappable{},
1818
dyno::Destructible{},
1919
dyno::Storable{},
20-
"f1"_s = dyno::function<void(dyno::T&)>,
21-
"f2"_s = dyno::function<void(dyno::T&)>,
22-
"f3"_s = dyno::function<void(dyno::T&)>,
23-
"f4"_s = dyno::function<void(dyno::T&)>
20+
"f1"_dyno = dyno::function<void(dyno::T&)>,
21+
"f2"_dyno = dyno::function<void(dyno::T&)>,
22+
"f3"_dyno = dyno::function<void(dyno::T&)>,
23+
"f4"_dyno = dyno::function<void(dyno::T&)>
2424
)) { };
2525

2626
template <typename T>
2727
auto const dyno::default_concept_map<Concept, T> = dyno::make_concept_map(
28-
"f1"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
29-
"f2"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
30-
"f3"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
31-
"f4"_s = [](T& self) { ++self; benchmark::DoNotOptimize(self); }
28+
"f1"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
29+
"f2"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
30+
"f3"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); },
31+
"f4"_dyno = [](T& self) { ++self; benchmark::DoNotOptimize(self); }
3232
);
3333

3434
template <typename VTablePolicy>
@@ -38,10 +38,10 @@ struct model {
3838
: poly_{std::move(t)}
3939
{ }
4040

41-
void f1() { poly_.virtual_("f1"_s)(poly_); }
42-
void f2() { poly_.virtual_("f2"_s)(poly_); }
43-
void f3() { poly_.virtual_("f3"_s)(poly_); }
44-
void f4() { poly_.virtual_("f4"_s)(poly_); }
41+
void f1() { poly_.virtual_("f1"_dyno)(poly_); }
42+
void f2() { poly_.virtual_("f2"_dyno)(poly_); }
43+
void f3() { poly_.virtual_("f3"_dyno)(poly_); }
44+
void f4() { poly_.virtual_("f4"_dyno)(poly_); }
4545

4646
private:
4747
dyno::poly<Concept, dyno::local_storage<8>, VTablePolicy> poly_;

0 commit comments

Comments
 (0)