zookeeper-cpp
ZooKeeper Client for C++
buffer.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <zk/config.hpp>
7 
8 #include <type_traits>
9 
18 #ifndef ZKPP_BUFFER_USE_CUSTOM
19 # define ZKPP_BUFFER_USE_CUSTOM 0
20 #endif
21 
25 #ifndef ZKPP_BUFFER_USE_STD_VECTOR
26 # if ZKPP_BUFFER_USE_CUSTOM
27 # define ZKPP_BUFFER_USE_STD_VECTOR 0
28 # else
29 # define ZKPP_BUFFER_USE_STD_VECTOR 1
30 # endif
31 #endif
32 
33 #if ZKPP_BUFFER_USE_STD_VECTOR
34 # define ZKPP_BUFFER_INCLUDE <vector>
35 # define ZKPP_BUFFER_TYPE std::vector<char>
36 #elif ZKPP_BUFFER_USE_CUSTOM
37 # if !defined ZKPP_BUFFER_INCLUDE || !defined ZKPP_BUFFER_TYPE
38 # error "When ZKPP_BUFFER_USE_CUSTOM is set, you must also define ZKPP_BUFFER_INCLUDE and ZKPP_BUFFER_TYPE"
39 # endif
40 #else
41 # error "Unknown type to use for zk::buffer"
42 #endif
43 
46 #include ZKPP_BUFFER_INCLUDE
47 
48 namespace zk
49 {
50 
67 using buffer = ZKPP_BUFFER_TYPE;
68 
69 // Check through static_assert:
70 static_assert(sizeof(buffer::value_type) == 1, "buffer::value_type must be single-byte elements");
71 static_assert(std::is_same<std::size_t, buffer::size_type>::value, "buffer::size_type must be std::size_t");
72 static_assert(std::is_constructible<buffer, ptr<const buffer::value_type>, ptr<const buffer::value_type>>::value,
73  "buffer must be constructible with two pointers"
74  );
75 static_assert(std::is_move_constructible<buffer>::value, "buffer must be move-constructible");
76 static_assert(std::is_same<decltype(std::declval<const buffer&>().size()), buffer::size_type>::value,
77  "buffer::size() must return buffer::size_type"
78  );
79 static_assert(std::is_constructible<ptr<const buffer::value_type>,
80  decltype(std::declval<const buffer&>().data())
81  >::value,
82  "buffer::data() must return ptr<const buffer::value_type>"
83  );
84 
87 }
T * ptr
A simple, unowned pointer.
Definition: config.hpp:75
Definition: acl.cpp:8
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:67