-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathcollectors.h
More file actions
82 lines (69 loc) · 1.65 KB
/
collectors.h
File metadata and controls
82 lines (69 loc) · 1.65 KB
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
#ifndef SQLITE_COLLECTORS_H
#define SQLITE_COLLECTORS_H
#include <sqlite_modern_cpp.h>
#if __cplusplus > 201402
#define CPP14_SUPPORTED
#endif
#ifdef CPP14_SUPPORTED
#define __COLLECTOR_RETURN_TYPE auto
#define __COLLECTOR_CTOR_OF_T(T,X) {X}
#else
#define __COLLECTOR_RETURN_TYPE std::function<void(Args...)>
#define __COLLECTOR_CTOR_OF_T(T,X) T(X)
#endif
template <typename ...Args>
struct collect
{
template<typename T, template<class, class...> class C>
inline static
__COLLECTOR_RETURN_TYPE
to(C<T> &container)
{
return [&container](const Args&... args)
{
container.push_back(__COLLECTOR_CTOR_OF_T(T,args...));
};
}
template<typename T, template<class, class...> class C>
inline static
__COLLECTOR_RETURN_TYPE
to(C<std::shared_ptr<T>> &container)
{
return [&container](const Args&... args)
{
container.push_back(std::make_shared<T>(args...));
};
}
template<template<class, class...> class C, typename T >
struct as
{
friend C<T> operator>>(sqlite::database_binder& db_binder, as<C,T>)
{
C<T> container;
db_binder>>to(container);
return container;
}
friend C<T> operator>>(sqlite::database_binder&& db_binder, as<C,T>)
{
return db_binder>>as<C,T>();
}
};
template<typename T >
struct as<std::shared_ptr,T>
{
friend std::shared_ptr<T> operator>>(sqlite::database_binder& db_binder, as<std::shared_ptr,T>)
{
std::shared_ptr<T> objP;
db_binder>>[&objP](Args... args)
{
objP = std::make_shared<T>(args...);
};
return objP;
}
friend std::shared_ptr<T> operator>>(sqlite::database_binder&& db_binder, as<std::shared_ptr,T> whatever)
{
return db_binder>>whatever;
}
};
};
#endif