|
8 | 8 | // http://www.boost.org/LICENSE_1_0.txt)
|
9 | 9 |
|
10 | 10 | #include <boost/network/support/is_async.hpp>
|
| 11 | +#include <boost/network/support/is_pod.hpp> |
| 12 | +#include <boost/utility/enable_if.hpp> |
| 13 | +#include <boost/mpl/and.hpp> |
| 14 | +#include <boost/mpl/not.hpp> |
11 | 15 |
|
12 | 16 | namespace boost { namespace network {
|
13 | 17 |
|
14 | 18 | namespace impl {
|
15 |
| - template <class Message, class KeyType, class ValueType> |
16 |
| - inline void add_header(Message const & message, KeyType const & key, ValueType const & value, tags::default_string const &, mpl::false_ const &) { |
| 19 | + template <class Message, class KeyType, class ValueType, class Tag> |
| 20 | + inline typename enable_if< |
| 21 | + mpl::and_< |
| 22 | + mpl::not_<is_pod<Tag> > |
| 23 | + , mpl::not_<is_async<Tag> > |
| 24 | + > |
| 25 | + , void |
| 26 | + >::type |
| 27 | + add_header(Message & message, KeyType const & key, ValueType const & value, Tag) { |
17 | 28 | message.headers().insert(std::make_pair(key, value));
|
18 | 29 | }
|
19 | 30 |
|
20 |
| - template <class Message, class KeyType, class ValueType> |
21 |
| - inline void add_header(Message const & message, KeyType const & key, ValueType const & value, tags::default_wstring const &, mpl::false_ const &) { |
22 |
| - message.headers().insert(std::make_pair(key, value)); |
| 31 | + template <class Message, class KeyType, class ValueType, class Tag> |
| 32 | + inline typename enable_if< |
| 33 | + mpl::and_< |
| 34 | + mpl::not_<is_pod<Tag> > |
| 35 | + , is_async<Tag> |
| 36 | + > |
| 37 | + , void |
| 38 | + >::type |
| 39 | + add_header(Message & message, KeyType const & key, ValueType const & value, Tag) { |
| 40 | + typedef typename Message::header_type header_type; |
| 41 | + message.add_header(header_type(key,value)); |
23 | 42 | }
|
24 | 43 |
|
25 |
| - template <class Message, class KeyType, class ValueType> |
26 |
| - inline void add_header(Message const & message, KeyType const & key, ValueType const & value, tags::async const &, mpl::true_ const &) { |
27 |
| - message.add_header(std::make_pair(key, value)); |
| 44 | + template <class Message, class KeyType, class ValueType, class Tag> |
| 45 | + inline typename enable_if< |
| 46 | + is_pod<Tag> |
| 47 | + , void |
| 48 | + >::type |
| 49 | + add_header(Message & message, KeyType const & key, ValueType const & value, Tag) { |
| 50 | + typename Message::header_type header = { key, value }; |
| 51 | + message.headers.insert(message.headers.end(), header); |
28 | 52 | }
|
29 | 53 |
|
30 | 54 | }
|
31 | 55 |
|
32 | 56 | template <class Tag, template <class> class Message, class KeyType, class ValueType>
|
33 |
| - inline void add_header(Message<Tag> const & message, KeyType const & key, ValueType const & value) { |
34 |
| - impl::add_header(message, key, value, Tag(), is_async<Tag>()); |
| 57 | + inline void add_header(Message<Tag> & message, KeyType const & key, ValueType const & value) { |
| 58 | + impl::add_header(message, key, value, Tag()); |
35 | 59 | }
|
36 | 60 |
|
37 | 61 | } // namespace network
|
|
0 commit comments