- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 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 29.09.2021 20:39 # +2
CEHT9I6PbCKuu_nemyx 30.09.2021 20:52 # +2
Soul_re@ver 30.09.2021 21:01 # +4
> std::enable_if
> <vector>
У меня в «Си» такой хуйни нет
CEHT9I6PbCKuu_nemyx 30.09.2021 21:30 # +2
Вот с paamayim nekudotayim не знаю, что делать.