websocketpp  0.3.0
C++/Boost Asio based websocket client/server library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
cpp11.hpp
1 /*
2  * Copyright (c) 2013, Peter Thorson. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the WebSocket++ Project nor the
12  * names of its contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef WEBSOCKETPP_COMMON_CPP11_HPP
29 #define WEBSOCKETPP_COMMON_CPP11_HPP
30 
35 // Hide clang feature detection from other compilers
36 #ifndef __has_feature // Optional of course.
37  #define __has_feature(x) 0 // Compatibility with non-clang compilers.
38 #endif
39 #ifndef __has_extension
40  #define __has_extension __has_feature // Compatibility with pre-3.0 compilers.
41 #endif
42 
43 
44 #if defined(_WEBSOCKETPP_CPP11_STL_) || __cplusplus >= 201103L
45  // _WEBSOCKETPP_CPP11_STL_ is a flag from the build system that forces
46  // WebSocket++ into C++11 mode. __cplusplus is a define set by the compiler
47  // if it has full support for C++11 language features. If either are set use
48  // C++11 language features
49  #ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_
50  #define _WEBSOCKETPP_NOEXCEPT_TOKEN_ noexcept
51  #endif
52  #ifndef _WEBSOCKETPP_CONSTEXPR_TOKEN_
53  #define _WEBSOCKETPP_CONSTEXPR_TOKEN_ constexpr
54  #endif
55  #ifndef _WEBSOCKETPP_INITIALIZER_LISTS_
56  #define _WEBSOCKETPP_INITIALIZER_LISTS_
57  #endif
58  #ifndef _WEBSOCKETPP_NULLPTR_TOKEN_
59  #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
60  #endif
61 #else
62  // Test for noexcept
63  #ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_
64  #ifdef _WEBSOCKETPP_NOEXCEPT_
65  // build system says we have noexcept
66  #define _WEBSOCKETPP_NOEXCEPT_TOKEN_ noexcept
67  #else
68  #if __has_feature(cxx_noexcept)
69  // clang feature detect says we have noexcept
70  #define _WEBSOCKETPP_NOEXCEPT_TOKEN_ noexcept
71  #else
72  // assume we don't have noexcept
73  #define _WEBSOCKETPP_NOEXCEPT_TOKEN_
74  #endif
75  #endif
76  #endif
77 
78  // Test for constexpr
79  #ifndef _WEBSOCKETPP_CONSTEXPR_TOKEN_
80  #ifdef _WEBSOCKETPP_CONSTEXPR_
81  // build system says we have constexpr
82  #define _WEBSOCKETPP_CONSTEXPR_TOKEN_ constexpr
83  #else
84  #if __has_feature(cxx_constexpr)
85  // clang feature detect says we have constexpr
86  #define _WEBSOCKETPP_CONSTEXPR_TOKEN_ constexpr
87  #else
88  // assume we don't have constexpr
89  #define _WEBSOCKETPP_CONSTEXPR_TOKEN_
90  #endif
91  #endif
92  #endif
93 
94  // Enable initializer lists on clang when available.
95  #if __has_feature(cxx_generalized_initializers) && !defined(_WEBSOCKETPP_INITIALIZER_LISTS_)
96  #define _WEBSOCKETPP_INITIALIZER_LISTS_
97  #endif
98 
99  // Test for nullptr
100  #ifndef _WEBSOCKETPP_NULLPTR_TOKEN_
101  #ifdef _WEBSOCKETPP_NULLPTR_
102  // build system says we have nullptr
103  #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
104  #else
105  #if __has_feature(cxx_nullptr)
106  // clang feature detect says we have nullptr
107  #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
108  #elif _MSC_VER >= 1600
109  // Visual Studio version that has nullptr
110  #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
111  #else
112  // assume we don't have nullptr
113  #define _WEBSOCKETPP_NULLPTR_TOKEN_ 0
114  #endif
115  #endif
116  #endif
117 #endif
118 
119 #endif // WEBSOCKETPP_COMMON_CPP11_HPP