forked from expertisesolutions/cpp-generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverse.hh
40 lines (33 loc) · 1.26 KB
/
reverse.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#if !defined(REVERSE_HH)
#define REVERSE_HH
#include <generator.hpp>
// #include <sequence.hpp>
#include <attributes.hpp>
struct reverse_generator
{
template<typename OutputIterator, typename Context>
bool generate(OutputIterator sink, std::string const& value, Context const& context) const
{
for (int i = value.length() - 1; i >= 0; i--)
*sink++ = value[i];
return true;
}
} const reverse;
// Extras tags to mark `reverse_generator` as an actual generator.
namespace efl { namespace eolian { namespace grammar {
// Means this operator should be evaluated as is and is not replaced by a custom
// `U as_generator(T g)` call, like we will do belo when dealing with generators
// with parameters.
template<>
struct is_eager_generator<::reverse_generator> : std::true_type {};
// Tag used inside some operators to make sure T is a generator
template<>
struct is_generator<::reverse_generator> : std::true_type {};
namespace type_traits {
// This generator will consume 1 attribute from the attribute tuple passed
// to `generate(sink, params, context)`.
template<>
struct attributes_needed<::reverse_generator> : std::integral_constant<int, 1> {};
}
}}}
#endif // REVERSE_HH