Skip to content

Commit 861037f

Browse files
committed
trailing return types
1 parent 3cbedda commit 861037f

Some content is hidden

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

64 files changed

+536
-561
lines changed

ce/2-method-vptr-final.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ register_classes(Animal, Dog, Cat);
2222
using yorel::yomm2::virtual_ptr;
2323

2424
declare_method(
25-
void, meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream&));
25+
meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream&), void);
2626

2727
define_method(
28-
void, meet, (virtual_ptr<Cat> a1, virtual_ptr<Cat> a2, std::ostream& os)) {
28+
meet, (virtual_ptr<Cat> a1, virtual_ptr<Cat> a2, std::ostream& os), void) {
2929
os << a1->name << " ignores " << a2->name << "\n";
3030
}
3131

3232
define_method(
33-
void, meet, (virtual_ptr<Dog> a1, virtual_ptr<Cat> a2, std::ostream& os)) {
33+
meet, (virtual_ptr<Dog> a1, virtual_ptr<Cat> a2, std::ostream& os), void) {
3434
os << a1->name << " chases " << a2->name << "\n";
3535
}
3636

3737
define_method(
38-
void, meet, (virtual_ptr<Cat> a1, virtual_ptr<Dog> a2, std::ostream& os)) {
38+
meet, (virtual_ptr<Cat> a1, virtual_ptr<Dog> a2, std::ostream& os), void) {
3939
os << a1->name << " runs away from " << a2->name << "\n";
4040
}
4141

4242
define_method(
43-
void, meet, (virtual_ptr<Dog> a1, virtual_ptr<Dog> a2, std::ostream& os)) {
43+
meet, (virtual_ptr<Dog> a1, virtual_ptr<Dog> a2, std::ostream& os), void) {
4444
os << a1->name << " wags tail at " << a2->name << "\n";
4545
}
4646

ce/2-method-vptr.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,30 @@ register_classes(Animal, Dog, Cat);
2424
using yorel::yomm2::virtual_ptr;
2525

2626
declare_method(
27-
void, meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream&));
27+
meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream&), void);
2828

2929
define_method(
30-
void, meet, (virtual_ptr<Cat> a1, virtual_ptr<Cat> a2, std::ostream& os)) {
30+
meet, (virtual_ptr<Cat> a1, virtual_ptr<Cat> a2, std::ostream& os), void) {
3131
os << a1->name << " ignores " << a2->name << "\n";
3232
}
3333

3434
define_method(
35-
void, meet, (virtual_ptr<Dog> a1, virtual_ptr<Cat> a2, std::ostream& os)) {
35+
meet, (virtual_ptr<Dog> a1, virtual_ptr<Cat> a2, std::ostream& os), void) {
3636
os << a1->name << " chases " << a2->name << "\n";
3737
}
3838

3939
define_method(
40-
void, meet, (virtual_ptr<Cat> a1, virtual_ptr<Dog> a2, std::ostream& os)) {
40+
meet, (virtual_ptr<Cat> a1, virtual_ptr<Dog> a2, std::ostream& os), void) {
4141
os << a1->name << " runs away from " << a2->name << "\n";
4242
}
4343

4444
define_method(
45-
void, meet, (virtual_ptr<Dog> a1, virtual_ptr<Dog> a2, std::ostream& os)) {
45+
meet, (virtual_ptr<Dog> a1, virtual_ptr<Dog> a2, std::ostream& os), void) {
4646
os << a1->name << " wags tail at " << a2->name << "\n";
4747
}
4848

49-
void meet_animals(const std::vector<virtual_ptr<Animal>>& animals, std::ostream& os) {
49+
void meet_animals(
50+
const std::vector<virtual_ptr<Animal>>& animals, std::ostream& os) {
5051
for (auto animal : animals) {
5152
for (auto other : animals) {
5253
if (&animal != &other) {

ce/2-method.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ struct Cat : Animal {
2222
register_classes(Animal, Dog, Cat);
2323

2424
declare_method(
25-
void, meet, (virtual_<Animal&>, virtual_<Animal&>, std::ostream&));
25+
meet, (virtual_<Animal&>, virtual_<Animal&>, std::ostream&), void);
2626

27-
define_method(void, meet, (Cat& a1, Cat& a2, std::ostream& os)) {
27+
define_method(meet, (Cat & a1, Cat& a2, std::ostream& os), void) {
2828
os << a1.name << " ignores " << a2.name << "\n";
2929
}
3030

31-
define_method(void, meet, (Dog& a1, Cat& a2, std::ostream& os)) {
31+
define_method(meet, (Dog & a1, Cat& a2, std::ostream& os), void) {
3232
os << a1.name << " chases " << a2.name << "\n";
3333
}
3434

35-
define_method(void, meet, (Cat& a1, Dog& a2, std::ostream& os)) {
35+
define_method(meet, (Cat & a1, Dog& a2, std::ostream& os), void) {
3636
os << a1.name << " runs away from " << a2.name << "\n";
3737
}
3838

39-
define_method(void, meet, (Dog& a1, Dog& a2, std::ostream& os)) {
39+
define_method(meet, (Dog & a1, Dog& a2, std::ostream& os), void) {
4040
os << a1.name << " wags tail at " << a2.name << "\n";
4141
}
4242

4343
void meet_animals(const std::vector<Animal*>& animals, std::ostream& os) {
4444
for (auto animal : animals) {
4545
for (auto other : animals) {
46-
if (&animal !=&other) {
46+
if (&animal != &other) {
4747
meet(*animal, *other, os);
4848
}
4949
}
@@ -55,7 +55,7 @@ int main() {
5555

5656
Dog hector{"Hector"}, snoopy{"Snoopy"};
5757
Cat felix{"Felix"}, sylvester{"Sylvester"};
58-
std::vector<Animal*> animals = {&hector,&felix,&sylvester,&snoopy};
58+
std::vector<Animal*> animals = {&hector, &felix, &sylvester, &snoopy};
5959

6060
meet_animals(animals, std::cout);
6161
}

ce/uni-method-vptr-final.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ struct Cat : Animal {
2020

2121
register_classes(Animal, Dog, Cat);
2222

23-
using yorel::yomm2::virtual_ptr;
2423
using yorel::yomm2::final_virtual_ptr;
24+
using yorel::yomm2::virtual_ptr;
2525

26-
declare_method(void, kick, (virtual_ptr<Animal>, std::ostream&));
26+
declare_method(kick, (virtual_ptr<Animal>, std::ostream&), void);
2727

28-
define_method(void, kick, (virtual_ptr<Cat> animal, std::ostream& os)) {
28+
define_method(kick, (virtual_ptr<Cat> animal, std::ostream& os), void) {
2929
os << animal->name << " hisses.\n";
3030
}
3131

32-
define_method(void, kick, (virtual_ptr<Dog> animal, std::ostream& os)) {
32+
define_method(kick, (virtual_ptr<Dog> animal, std::ostream& os), void) {
3333
os << animal->name << " barks.\n";
3434
}
3535

ce/uni-method-vptr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ struct Animal {
77
const char* name;
88
Animal(const char* name) : name(name) {
99
}
10-
virtual ~Animal() {}
10+
virtual ~Animal() {
11+
}
1112
};
1213

1314
struct Dog : Animal {
@@ -22,13 +23,13 @@ register_classes(Animal, Dog, Cat);
2223

2324
using yorel::yomm2::virtual_ptr;
2425

25-
declare_method(void, kick, (virtual_ptr<Animal>, std::ostream&));
26+
declare_method(kick, (virtual_ptr<Animal>, std::ostream&), void);
2627

27-
define_method(void, kick, (virtual_ptr<Cat> animal, std::ostream& os)) {
28+
define_method(kick, (virtual_ptr<Cat> animal, std::ostream& os), void) {
2829
os << animal->name << " hisses.\n";
2930
}
3031

31-
define_method(void, kick, (virtual_ptr<Dog> animal, std::ostream& os)) {
32+
define_method(kick, (virtual_ptr<Dog> animal, std::ostream& os), void) {
3233
os << animal->name << " barks.\n";
3334
}
3435

ce/uni-method.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ struct Cat : Animal {
2121

2222
register_classes(Animal, Dog, Cat);
2323

24-
declare_method(void, kick, (virtual_<Animal&>, std::ostream&));
24+
declare_method(kick, (virtual_<Animal&>, std::ostream&), void);
2525

26-
define_method(void, kick, (Cat& animal, std::ostream& os)) {
26+
define_method(kick, (Cat & animal, std::ostream& os), void) {
2727
os << animal.name << " hisses.\n";
2828
}
2929

30-
define_method(void, kick, (Dog& animal, std::ostream& os)) {
30+
define_method(kick, (Dog & animal, std::ostream& os), void) {
3131
os << animal.name << " barks.\n";
3232
}
3333

docs.in/reference/declare_static_method.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ headers: yorel/yomm2/cute.hpp, yorel/yomm2.hpp
55
hrefs: YOMM2_STATIC_DECLARE
66

77
```c++
8-
#define declare_static_method(return-type, name, (types)) /*unspecified*/
8+
#define declare_static_method(name, (types), return-type) /*unspecified*/
99
```
1010

1111
Declare a method as a static member in a `struct` or `class`. Otherwise, the
@@ -34,25 +34,25 @@ struct SeniorEngineer : Engineer {};
3434

3535
register_classes(Engineer, SeniorEngineer);
3636

37-
declare_method(std::string, speak, (virtual_<const Engineer&>));
37+
declare_method(speak, (virtual_<const Engineer&>), std::string);
3838

39-
define_method(std::string, speak, (const Engineer&)) {
39+
define_method(speak, (const Engineer&), std::string) {
4040
return "engineers love ADL";
4141
}
4242

43-
define_method(std::string, speak, (const SeniorEngineer& engineer)) {
43+
define_method(speak, (const SeniorEngineer& engineer), std::string) {
4444
return "senior " + next(engineer);
4545
}
4646

4747
struct no_adl {
48-
declare_static_method(std::string, speak, (virtual_<const Engineer&>));
48+
declare_static_method(speak, (virtual_<const Engineer&>), std::string);
4949
};
5050

51-
define_method(std::string, no_adl::speak, (const Engineer&)) {
51+
define_method(no_adl::speak, (const Engineer&), std::string) {
5252
return "engineers hate ADL";
5353
}
5454

55-
define_method(std::string, no_adl::speak, (const SeniorEngineer& engineer)) {
55+
define_method(no_adl::speak, (const SeniorEngineer& engineer), std::string) {
5656
return "senior " + next(engineer);
5757
}
5858

docs.in/reference/define_method.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ headers: yorel/yomm2/cute.hpp, yorel/yomm2.hpp></sub
1212
### Usage
1313

1414
```
15-
define_method(return-type, name, (method-parameter-list)) {
15+
define_method(name, (method-parameter-list), return-type) {
1616
...
1717
}
1818

19-
define_method(container, return-type, name, (method-parameter-list)) {
19+
define_method(return-type, name, container, (method-parameter-list)) {
2020
...
2121
}
2222
```
@@ -63,13 +63,13 @@ struct Bulldog : Dog {};
6363

6464
register_classes(Animal, Dog, Bulldog);
6565

66-
declare_method(std::string, kick, (virtual_<Animal*>));
66+
declare_method(kick, (virtual_<Animal*>), std::string);
6767

68-
define_method(std::string, kick, (Dog* dog)) {
68+
define_method(kick, (Dog* dog), std::string) {
6969
return "bark";
7070
}
7171

72-
define_method(std::string, kick, (Bulldog* dog)) {
72+
define_method(kick, (Bulldog* dog), std::string) {
7373
return next(dog) + " and bite";
7474
}
7575

docs.in/reference/method.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ using yomm2::virtual_;
192192
YOMM2_STATIC(yomm2::use_classes<Animal, Cat, Dog, Bulldog>);
193193

194194
struct kick_methods;
195-
using kick = yomm2::method<kick_methods, std::string(virtual_<Animal&>)>;
195+
using kick = yomm2::method<kick_methods(virtual_<Animal&>), std::string>;
196196

197197
std::string kick_cat(Cat& dog) { return "hiss"; }
198198
YOMM2_STATIC(kick::override_fn<kick_cat>);
@@ -206,7 +206,7 @@ struct kick_bulldog : kick::with_next<kick_bulldog> {
206206
YOMM2_STATIC(kick::override<kick_bulldog>);
207207

208208
struct YOMM2_SYMBOL(pet); // use obfuscated name
209-
using pet = yomm2::method<YOMM2_SYMBOL(pet), std::string(virtual_<Animal&>)>;
209+
using pet = yomm2::method<YOMM2_SYMBOL(pet)(virtual_<Animal&>), std::string>;
210210

211211
std::string pet_cat(Cat& dog) { return "purr"; }
212212
YOMM2_STATIC(pet::override_fn<pet_cat>);

docs.in/reference/method_class.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ macro: YOMM2_METHOD_CLASS
55
headers: yorel/yomm2/macros.hpp
66
77
```c++
8-
#define method_class(RETURN_TYPE, NAME, ARGS [, POLICY])
9-
#define YOMM2_METHOD_CLASS(RETURN_TYPE, NAME, ARGS [, POLICY])
8+
#define method_class(NAME, ARGS [, POLICY], RETURN_TYPE)
9+
#define YOMM2_METHOD_CLASS(NAME, ARGS [, POLICY], RETURN_TYPE)
1010
```
1111
1212
Both macros take the same arguments as ->`declare_method`, and return the
@@ -32,17 +32,17 @@ struct Dog : Animal {};
3232

3333
register_classes(Animal, Dog);
3434

35-
declare_method(std::string, kick, (virtual_<Animal&>));
35+
declare_method(kick, (virtual_<Animal&>), std::string);
3636

37-
define_method(std::string, kick, (Dog & dog)) {
37+
define_method(kick, (Dog & dog), std::string) {
3838
return "bark";
3939
}
4040

4141
BOOST_AUTO_TEST_CASE(ref_method_class) {
4242
yorel::yomm2::initialize();
4343

4444
Animal&& dog = Dog();
45-
using X = YOMM2_METHOD_CLASS(std::string, kick, (virtual_<Animal&>));
46-
auto reply = YOMM2_METHOD_CLASS(std::string, kick, (virtual_<Animal&>))::fn(dog);
45+
using X = YOMM2_METHOD_CLASS(kick, (virtual_<Animal&>), std::string);
46+
auto reply = YOMM2_METHOD_CLASS(kick, (virtual_<Animal&>), std::string)::fn(dog);
4747
BOOST_TEST(reply == "bark");
4848
}

docs.in/reference/method_container.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ class Animal {
4848
std::string name;
4949

5050
public:
51-
explicit Animal(const std::string& name) : name(name) {}
52-
virtual ~Animal() {}
51+
explicit Animal(const std::string& name) : name(name) {
52+
}
53+
virtual ~Animal() {
54+
}
5355

5456
friend_method(kicks);
5557
};
@@ -64,14 +66,14 @@ class Bulldog : public Dog {
6466

6567
register_classes(Animal, Dog, Bulldog);
6668

67-
declare_method(std::string, kick, (virtual_<Animal*>));
69+
declare_method(kick, (virtual_<Animal*>), std::string);
6870

69-
define_method_inline(kicks, std::string, kick, (Dog* dog)) {
71+
define_method_inline(kicks, kick, (Dog * dog), std::string) {
7072
return dog->name + " barks";
7173
}
7274

73-
define_method(kicks, std::string, kick, (Bulldog* dog)) {
74-
return kicks<std::string(Dog*)>::fn(dog) + " and bites";
75+
define_method(kicks, kick, (Bulldog * dog), std::string) {
76+
return method_definition(kicks, kick, (Dog*))(dog) + " and bites";
7577
}
7678

7779
BOOST_AUTO_TEST_CASE(ref_example) {

docs.in/reference/policy-minimal_rtti.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ using vptr = virtual_ptr<Class, final_policy>;
5757

5858
register_classes(Animal, Dog, Cat, final_policy);
5959

60-
declare_method(std::string, kick, (vptr<Animal>), final_policy);
60+
declare_method(kick, (vptr<Animal>), std::string, final_policy);
6161

62-
define_method(std::string, kick, (vptr<Cat> cat)) {
62+
define_method(kick, (vptr<Cat> cat), std::string) {
6363
return "hiss";
6464
}
6565

66-
define_method(std::string, kick, (vptr<Dog> dog)) {
66+
define_method(kick, (vptr<Dog> dog), std::string) {
6767
return "bark";
6868
}
6969

docs.in/reference/policy-throw_error.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ using throw_policy = yomm2::default_policy::replace<
4949

5050
register_classes(Animal, Dog, throw_policy);
5151

52-
declare_method(void, kick, (virtual_<Animal&>), throw_policy);
52+
declare_method(kick, (virtual_<Animal&>), void, throw_policy);
5353

5454
BOOST_AUTO_TEST_CASE(ref_throw_error) {
5555
yomm2::initialize<throw_policy>();
@@ -64,8 +64,7 @@ BOOST_AUTO_TEST_CASE(ref_throw_error) {
6464
BOOST_TEST(
6565
error.method ==
6666
yomm2::type_id(
67-
&typeid(method_class(
68-
void, kick, (virtual_<Animal&>), throw_policy))));
67+
&typeid(method_class(kick, (virtual_<Animal&>), void, throw_policy))));
6968
BOOST_TEST(error.arity == 1);
7069
BOOST_TEST(error.types[0] == throw_policy::static_type<Dog>());
7170
threw = true;

0 commit comments

Comments
 (0)