- 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
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
#include <stdio.h>
#include <memory>
#define Property(type,name) type name;auto &set_##name(type val){name = val; return *this;}
#define Set(x,y) set_##x(y)
//#define Create(type, ...) (*(new type(__VA_ARGS__)))
template <typename T>
static inline T& Create_(const char *name)
{
return *(new T(name));
}
#define Create(type, ...) Create_<type>(__VA_ARGS__)
template <typename T>
static inline T CreateNoAlloc_(const char *name)
{
return T(name);
}
#define CreateNoAlloc(type, ...) CreateNoAlloc_<type>(__VA_ARGS__)
struct BaseItem
{
const char *Name;
BaseItem(const char *n): Name(n) {}
Property(int, Width);
Property(int, Height);
};
#include <vector>
struct Markup
{
std::vector<BaseItem*> Children;
template <typename T>
Markup &Add(T &item)
{
Children.push_back(&item);
return *this;
}
};
static inline Markup CreateMarkup(const char *n)
{
return Markup();
}
/*
struct Markup2
{
std::vector<std::shared_ptr<BaseItem>> Children;
template <typename T>
Markup2 &Add(T item)
{
Children.push_back(std::shared_ptr(&item));
return *this;
}
};
*/
template<std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
print(std::tuple<Tp...>& t)
{ }
template<std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I < sizeof...(Tp), void>::type
print(std::tuple<Tp...>& t)
{
printf("%s\n",std::get<I>(t).Name);
print<I + 1, Tp...>(t);
}
#include <string.h>
static BaseItem NOT_FOUND("NOT_FOUND");
template<typename T, std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
print1(std::tuple<Tp...>& t, const char *n)
{ }
template<typename T, std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I < sizeof...(Tp), T&>::type
print1(std::tuple<Tp...>& t, const char *n)
{
if( !strcmp(std::get<I>(t).Name, n))
return std::get<I>(t);
print1<T, I + 1, Tp...>(t,n);
return NOT_FOUND;
}
#define CreateMarkup(...) std::make_tuple(__VA_ARGS__)
#define AppendMarkup(src, ...) std::tuple_cat(src, std::make_tuple(__VA_ARGS__))
#define MarkupItem(markup,type,name,action) namespace {type &i = print1<type>(markup,name).action; }
auto markup1 = CreateMarkup(BaseItem("test").Set(Width,14), BaseItem("test2"));
auto markup2 = AppendMarkup(markup1,BaseItem("test3").Set(Width,15));
auto markup3 = markup1;
MarkupItem(markup3,BaseItem,"test2",Set(Width,16));
template <typename T>
rotoeb # 0
CEHT9I6PbCKuu_nemyx # 0 ⇈
[email protected] # 0
> std::enable_if
> <vector>
У меня в «Си» такой хуйни нет
CEHT9I6PbCKuu_nemyx # 0 ⇈
Вот с paamayim nekudotayim не знаю, что делать.