blob: c24b91b1c8187c65c8970e5b848b047d53b89850 [file] [log] [blame]
Roger Meier82525772012-11-16 00:38:27 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_CXXFUNCTIONAL_H_
21#define _THRIFT_CXXFUNCTIONAL_H_ 1
22
23/**
24 * Loads <functional> from the 'right' location, depending
25 * on compiler and whether or not it's using C++03 with TR1
26 * or C++11.
27 */
28
29/*
30 * MSVC 10 and 11 have the <functional> stuff at <functional>.
31 * In MSVC 10 all of the implementations live in std::tr1.
32 * In MSVC 11 all of the implementations live in std, with aliases
33 * in std::tr1 to point to the ones in std.
34 */
35#ifdef _WIN32
36 #define _THRIFT_USING_MICROSOFT_STDLIB 1
37#endif
38
39#ifdef __clang__
40 /* Clang has two options, depending on standard library:
41 * - no -stdlib or -stdlib=libstdc++ set; uses GNU libstdc++.
42 * <tr1/functional>
43 * - -stdlib=libc++; uses LLVM libc++.
44 * <functional>, no 'std::tr1'.
45 *
46 * The compiler itself doesn't define anything differently
47 * depending on the value of -stdlib, but the library headers
48 * will set different preprocessor options. In order to check,
49 * though, we have to pull in some library header.
50 */
51 #include <utility>
52
53 /* With LLVM libc++, utility pulls in __config, which sets
54 _LIBCPP_VERSION. */
55 #if defined(_LIBCPP_VERSION)
56 #define _THRIFT_USING_CLANG_LIBCXX 1
57
58 /* With GNU libstdc++, utility pulls in bits/c++config.h,
59 which sets __GLIBCXX__. */
60 #elif defined(__GLIBCXX__)
61 #define _THRIFT_USING_GNU_LIBSTDCXX 1
62
63 /* No idea. */
64 #else
65 #error Unable to detect which C++ standard library is in use.
66 #endif
67#elif __GNUC__
68 #define _THRIFT_USING_GNU_LIBSTDCXX 1
69#endif
70
71#if _THRIFT_USING_MICROSOFT_STDLIB
72 #include <functional>
73
74 namespace apache { namespace thrift { namespace stdcxx {
75 using ::std::tr1::function;
76 using ::std::tr1::bind;
77
78 namespace placeholders {
79 using ::std::tr1::placeholders::_1;
80 using ::std::tr1::placeholders::_2;
81 using ::std::tr1::placeholders::_3;
82 using ::std::tr1::placeholders::_4;
83 using ::std::tr1::placeholders::_5;
84 using ::std::tr1::placeholders::_6;
85 } // apache::thrift::stdcxx::placeholders
86 }}} // apache::thrift::stdcxx
87
88#elif _THRIFT_USING_CLANG_LIBCXX
89 #include <functional>
90
91 namespace apache { namespace thrift { namespace stdcxx {
92 using ::std::function;
93 using ::std::bind;
94
95 namespace placeholders {
96 using ::std::placeholders::_1;
97 using ::std::placeholders::_2;
98 using ::std::placeholders::_3;
99 using ::std::placeholders::_4;
100 using ::std::placeholders::_5;
101 using ::std::placeholders::_6;
102 } // apache::thrift::stdcxx::placeholders
103 }}} // apache::thrift::stdcxx
104
105#elif _THRIFT_USING_GNU_LIBSTDCXX
106 #include <tr1/functional>
107
108 namespace apache { namespace thrift { namespace stdcxx {
109 using ::std::tr1::function;
110 using ::std::tr1::bind;
111
112 namespace placeholders {
113 using ::std::tr1::placeholders::_1;
114 using ::std::tr1::placeholders::_2;
115 using ::std::tr1::placeholders::_3;
116 using ::std::tr1::placeholders::_4;
117 using ::std::tr1::placeholders::_5;
118 using ::std::tr1::placeholders::_6;
119 } // apache::thrift::stdcxx::placeholders
120 }}} // apache::thrift::stdcxx
121#endif
122
Roger Meierbb98ed42013-06-20 01:06:22 +0200123 // Alias for thrift c++ compatibility namespace
124 namespace tcxx = apache::thrift::stdcxx;
125
Roger Meier82525772012-11-16 00:38:27 +0000126#endif // #ifndef _THRIFT_CXXFUNCTIONAL_H_