Skip to content

Commit

Permalink
more macro work
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Sep 22, 2024
1 parent 2aa20c8 commit 6313a79
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 154 deletions.
2 changes: 2 additions & 0 deletions dev/presetgen
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ presets = {
"YOMM2_ENABLE_EXAMPLES": "ON",
"YOMM2_ENABLE_TESTS": "ON",
"YOMM2_ENABLE_BENCHMARKS": "ON",
"VCPKG_INSTALL_OPTIONS": "--allow-unsupported"

},
**tool_chain.configure_presets,
}
Expand Down
10 changes: 5 additions & 5 deletions docs.in/reference/YOMM2_SYMBOL.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifdef YOMM2_MD

macro: YOMM2_SYMBOL
macro: YOMM2_NAME
headers: yorel/yomm2/symbols.hpp, yorel/yomm2.hpp

```c++
#define YOMM2_SYMBOL(seed) /*unspecified*/
#define YOMM2_NAME(seed) /*unspecified*/
```

Macro `YOMM2_SYMBOL` expands to an obfuscated symbol, unlikely
Macro `YOMM2_NAME` expands to an obfuscated symbol, unlikely
to clash with other names in scope.

## Example
Expand All @@ -23,9 +23,9 @@ to clash with other names in scope.

BOOST_AUTO_TEST_CASE(ref_example) {
int foo = 1;
int YOMM2_SYMBOL(foo) = 2;
int YOMM2_NAME(foo) = 2;
BOOST_TEST(foo == 1);
BOOST_TEST(YOMM2_SYMBOL(foo) == 2);
BOOST_TEST(YOMM2_NAME(foo) == 2);
}

#endif
6 changes: 3 additions & 3 deletions docs.in/reference/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ and [`method::override`](#override) class templates.
* **Name**: a type that differentiates methods with the same signature. It is
recommended to declare a class (there is no need to define it) for each method
name in the same namespace. ->YOMM2_SYMBOL can be used for that effect.
name in the same namespace. ->YOMM2_NAME can be used for that effect.
* **ReturnType**: the type of the value returned by the function, or void. May
not be `auto`.
Expand Down Expand Up @@ -205,8 +205,8 @@ struct kick_bulldog : kick::with_next<kick_bulldog> {
};
YOMM2_STATIC(kick::override<kick_bulldog>);

struct YOMM2_SYMBOL(pet); // use obfuscated name
using pet = yomm2::method<YOMM2_SYMBOL(pet)(virtual_<Animal&>), std::string>;
struct YOMM2_NAME(pet); // use obfuscated name
using pet = yomm2::method<YOMM2_NAME(pet)(virtual_<Animal&>), std::string>;

std::string pet_cat(Cat& dog) { return "purr"; }
YOMM2_STATIC(pet::override_fn<pet_cat>);
Expand Down
6 changes: 3 additions & 3 deletions docs.in/reference/method_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ the same namespace as the container itself.
#include <yorel/yomm2.hpp>
#include <yorel/yomm2/compiler.hpp>

template<typename> struct kicks;
template<typename...> struct kicks;

class Animal {
std::string name;
Expand All @@ -53,7 +53,7 @@ class Animal {
virtual ~Animal() {
}

template<typename> friend struct kicks;
template<typename...> friend struct kicks;
};

class Dog : public Animal {
Expand All @@ -73,7 +73,7 @@ define_method_inline(kicks, kick, (Dog * dog), std::string) {
}

define_method_in(kicks, kick, (Bulldog * dog), std::string) {
return kicks<std::string (Dog*)>::fn(dog) + " and bites";
return kicks<YOMM2_NAME(kick)(Dog*)>::fn(dog) + " and bites";
}

BOOST_AUTO_TEST_CASE(ref_example) {
Expand Down
4 changes: 2 additions & 2 deletions docs.in/reference/use_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ using boost::mp11::mp_list;
use_classes<abstract_matrix, ordinary_matrix, square_matrix, sparse_matrix>
YOMM2_GENSYM;

struct YOMM2_SYMBOL(same_type);
using same_type = method<YOMM2_SYMBOL(same_type)(
struct YOMM2_NAME(same_type);
using same_type = method<YOMM2_NAME(same_type)(
virtual_<const abstract_matrix&>, virtual_<const abstract_matrix&>), bool>;

// 1 - see notes below
Expand Down
6 changes: 3 additions & 3 deletions docs.in/tutorials/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(test_synopsis_functions_no_macros) {
// - `YOMM2_STATIC(...)` expands to `static __VA_ARGS__ YOMM2_GENSYM`, i.e. it
// creates a static object of the type specified as macro parameters.

// - `YOMM2_SYMBOL(name)` expands to an obfuscated version of `name`. It is used
// - `YOMM2_NAME(name)` expands to an obfuscated version of `name`. It is used
// for the method key and the guide function.

// In addition, the header provides
Expand Down Expand Up @@ -241,9 +241,9 @@ using namespace yorel::yomm2;

YOMM2_STATIC(use_classes<Animal, Dog, Bulldog>);

struct YOMM2_SYMBOL(kick);
struct YOMM2_NAME(kick);

using kick = method<YOMM2_SYMBOL(kick)(virtual_<Animal&>), std::string>;
using kick = method<YOMM2_NAME(kick)(virtual_<Animal&>), std::string>;

// >

Expand Down
20 changes: 10 additions & 10 deletions docs.in/tutorials/templates_tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,26 @@ vector reals(new concrete_vector<double>{4., 5., 6.});

using namespace yorel::yomm2;

struct YOMM2_SYMBOL(addition);
struct YOMM2_NAME(addition);

using addition = method<
YOMM2_SYMBOL(addition)(
YOMM2_NAME(addition)(
virtual_<abstract_vector&>,
virtual_<abstract_vector&>),
vector>;

struct YOMM2_SYMBOL(subtraction);
struct YOMM2_NAME(subtraction);

using subtraction = method<
YOMM2_SYMBOL(subtraction)(
YOMM2_NAME(subtraction)(
virtual_<abstract_vector&>,
virtual_<abstract_vector&>),
vector>;

struct YOMM2_SYMBOL(comparison);
struct YOMM2_NAME(comparison);

using comparison = method<
YOMM2_SYMBOL(comparison)(
YOMM2_NAME(comparison)(
virtual_<abstract_vector&>,
virtual_<abstract_vector&>),
bool>;
Expand Down Expand Up @@ -882,11 +882,11 @@ BOOST_AUTO_TEST_CASE(test_static_operations) {

// code<

struct YOMM2_SYMBOL(transpose);
struct YOMM2_NAME(transpose);

template<typename Matrix>
using transpose =
method<YOMM2_SYMBOL(transpose)(virtual_<Matrix&>), handle<Matrix>>;
method<YOMM2_NAME(transpose)(virtual_<Matrix&>), handle<Matrix>>;

template<
template<typename> typename Matrix, typename T,
Expand Down Expand Up @@ -1134,11 +1134,11 @@ static_assert(

// code<

struct YOMM2_SYMBOL(add);
struct YOMM2_NAME(add);

template<typename M1, typename M2>
using add = method<
YOMM2_SYMBOL(add)(virtual_<M1&>, virtual_<M2&>),
YOMM2_NAME(add)(virtual_<M1&>, virtual_<M2&>),
handle<binary_result_type<M1, M2>>>;

template<
Expand Down
2 changes: 1 addition & 1 deletion examples/containers/arc_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define_method_in(
painters, paintObject, (Painter & painter, const geometries::Arc& arc),
void) {
++painter.counter;
painters<void(Painter&, const geometries::Line&)>::fn(painter, arc);
next(painter, arc);
std::cout << " " << "painting arc\n";
}

Expand Down
8 changes: 4 additions & 4 deletions examples/containers/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
namespace painter {

namespace paint1d {
template<typename> struct painters;
template<typename...> struct painters;
}
namespace paint2d {
template<typename> struct painters;
template<typename...> struct painters;
}

class Painter;
Expand All @@ -36,8 +36,8 @@ class Painter {

private:
int counter = 0;
template<typename> friend struct paint1d::painters;
friend paint2d::painters<void(Painter&, const geometries::Shape&)>;
template<typename...> friend struct paint1d::painters;
friend paint2d::painters<YOMM2_NAME(paintObject)(Painter&, const geometries::Shape&)>;
};

inline void Painter::paint(const geometries::Geometry& geometry) {
Expand Down
6 changes: 3 additions & 3 deletions examples/containers/segment_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ define_method_in(
painters, paintObject,
(Painter & painter, const geometries::Segment& segment), void) {
++painter.counter;
painters<void(Painter&, const geometries::Line&)>::fn(painter, segment);
std::cout << " "
<< "painting segment\n";
painters<YOMM2_NAME(paintObject)(Painter&, const geometries::Line&)>::fn(
painter, segment);
std::cout << " " << "painting segment\n";
}

} // namespace paint1d
Expand Down
1 change: 1 addition & 0 deletions include/yorel/yomm2/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ class method<Name(Parameters...), Return, Options...>

public:
// Public aliases.
using name_type = Name;
using return_type = Return;
using next_type =
Return (*)(detail::remove_virtual<Parameters>...) noexcept(NoExcept);
Expand Down
Loading

0 comments on commit 6313a79

Please sign in to comment.