I already saw this but as I wrote on-top
On 29.1.2018 at 2:39 PM, Shaarigan said:
I tried to implement them on an old machine without using any C++11/14/17
the drawback is that this (or better the compiler; thank you Microsoft) dosent support constexpr and is itself very ... bitchy .. (is that a word? )about compile time code verification. Thats why I needed to write a list of char literals instead of string even on the fact that I have a variadic macro replacement (like the one from boost) that already works and compiles oin different compilers (MSVC 2010, 2015, clang LLVM)
#ifndef LITERAL_MAX_LENGTH
#define LITERAL_MAX_LENGTH 70
#endif
struct ErrorType;
/**
A compile time expression
*/
template<char c, typename list> struct Expression
{
typedef ErrorType Result;
};
/*
define additional expressions here
template<typename list> struct Expression<'['>
{
typedef typename SequenceType<list::Head, List::Tail> Result;
};
*/
/**
A compile time static literal expression
*/
template<VARIADIC_PARAMS_PAIR(char c, = 0, LITERAL_MAX_LENGTH)> struct Literal;
#define LITERAL_DEFINITION(n) template<VARIADIC_PARAMS_ARGS(char c, n)> struct Literal<VARIADIC_PARAMS_ARGS(c, n)> \
{ \
enum { Head = (c0) }; \
typedef typename Literal<VARIADIC_PARAMS_SHIFT(c, n)> Tail; \
\
typedef typename Expression<Head, Tail>::Result Compile; \
static const char Value[n + 1]; \
}; \
template<VARIADIC_PARAMS_ARGS(char c, n)> const char Literal<VARIADIC_PARAMS_ARGS(c, n)>::Value[n + 1] = { VARIADIC_PARAMS_ARGS(c, n), 0 };
IT_FOR(DECREMENT(LITERAL_MAX_LENGTH), LITERAL_DEFINITION)
#define litexpr(...) Literal<__VA_ARGS__>
#undef LITERAL_DEFINITION
#undef LITERAL_MAX_LENGTH
But is still a bit tricky to use, even when going for the macro
litexpr('[','^',' ',']','*')::Compile //works but is ugly to use
litexpr("[^ ]*")::Compile //dosent work; MSVC complains until 2013 (constexpr isnt supported) and even sometimes in 2015 that this is not a compile time constant
What I like to achieve here is to have compile-time verified/ assembled expressions that could be used for example in a regulary test regex or something like a mesh; or in general to have compile-time expression code that is generated into runtime usable parser/verifier/lambda/<insert whatever here>. It dosent need to verify anything at compile-time but simply compile the expression into executable code. I know it is hard and tricky to get this running (and sometimes a waste of time) but its just an experimental feature to speed up things