libbf  0.1
 All Classes Functions Typedefs Friends Pages
wrap.h
1 #ifndef BF_WRAP_H
2 #define BF_WRAP_H
3 
4 #include <type_traits>
5 #include <vector>
6 #include <bf/object.h>
7 
8 namespace bf {
9 
10 template <
11  typename T,
12  typename = typename std::enable_if<std::is_arithmetic<T>::value>::type
13 >
14 object wrap(T const& x)
15 {
16  return {&x, sizeof(T)};
17 }
18 
19 template <
20  typename T,
21  size_t N,
22  typename = typename std::enable_if<std::is_arithmetic<T>::value>::type
23 >
24 object wrap(T const (&str)[N])
25 {
26  return {&str, N * sizeof(T)};
27 }
28 
29 template <
30  typename T,
31  typename = typename std::enable_if<std::is_arithmetic<T>::value>::type
32 >
33 object wrap(std::vector<T> const& s)
34 {
35  return {s.data(), s.size()};
36 }
37 
38 inline object wrap(std::string const& str)
39 {
40  return {str.data(), str.size()};
41 }
42 
43 } // namespace bf
44 
45 #endif