Roger Meier | 8252577 | 2012-11-16 00:38:27 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 23 | // clang-format off |
| 24 | |
Roger Meier | 8252577 | 2012-11-16 00:38:27 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Loads <functional> from the 'right' location, depending |
| 27 | * on compiler and whether or not it's using C++03 with TR1 |
| 28 | * or C++11. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * MSVC 10 and 11 have the <functional> stuff at <functional>. |
| 33 | * In MSVC 10 all of the implementations live in std::tr1. |
| 34 | * In MSVC 11 all of the implementations live in std, with aliases |
| 35 | * in std::tr1 to point to the ones in std. |
| 36 | */ |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 37 | #if defined(_WIN32) && !defined(__MINGW32__) |
Roger Meier | 8252577 | 2012-11-16 00:38:27 +0000 | [diff] [blame] | 38 | #define _THRIFT_USING_MICROSOFT_STDLIB 1 |
| 39 | #endif |
| 40 | |
| 41 | #ifdef __clang__ |
| 42 | /* Clang has two options, depending on standard library: |
| 43 | * - no -stdlib or -stdlib=libstdc++ set; uses GNU libstdc++. |
| 44 | * <tr1/functional> |
| 45 | * - -stdlib=libc++; uses LLVM libc++. |
| 46 | * <functional>, no 'std::tr1'. |
| 47 | * |
| 48 | * The compiler itself doesn't define anything differently |
| 49 | * depending on the value of -stdlib, but the library headers |
| 50 | * will set different preprocessor options. In order to check, |
| 51 | * though, we have to pull in some library header. |
| 52 | */ |
| 53 | #include <utility> |
| 54 | |
| 55 | /* With LLVM libc++, utility pulls in __config, which sets |
| 56 | _LIBCPP_VERSION. */ |
| 57 | #if defined(_LIBCPP_VERSION) |
| 58 | #define _THRIFT_USING_CLANG_LIBCXX 1 |
| 59 | |
| 60 | /* With GNU libstdc++, utility pulls in bits/c++config.h, |
| 61 | which sets __GLIBCXX__. */ |
| 62 | #elif defined(__GLIBCXX__) |
| 63 | #define _THRIFT_USING_GNU_LIBSTDCXX 1 |
| 64 | |
| 65 | /* No idea. */ |
| 66 | #else |
| 67 | #error Unable to detect which C++ standard library is in use. |
| 68 | #endif |
| 69 | #elif __GNUC__ |
| 70 | #define _THRIFT_USING_GNU_LIBSTDCXX 1 |
| 71 | #endif |
| 72 | |
| 73 | #if _THRIFT_USING_MICROSOFT_STDLIB |
| 74 | #include <functional> |
| 75 | |
| 76 | namespace apache { namespace thrift { namespace stdcxx { |
| 77 | using ::std::tr1::function; |
| 78 | using ::std::tr1::bind; |
| 79 | |
| 80 | namespace placeholders { |
| 81 | using ::std::tr1::placeholders::_1; |
| 82 | using ::std::tr1::placeholders::_2; |
| 83 | using ::std::tr1::placeholders::_3; |
| 84 | using ::std::tr1::placeholders::_4; |
| 85 | using ::std::tr1::placeholders::_5; |
| 86 | using ::std::tr1::placeholders::_6; |
| 87 | } // apache::thrift::stdcxx::placeholders |
| 88 | }}} // apache::thrift::stdcxx |
| 89 | |
| 90 | #elif _THRIFT_USING_CLANG_LIBCXX |
| 91 | #include <functional> |
| 92 | |
| 93 | namespace apache { namespace thrift { namespace stdcxx { |
| 94 | using ::std::function; |
| 95 | using ::std::bind; |
| 96 | |
| 97 | namespace placeholders { |
| 98 | using ::std::placeholders::_1; |
| 99 | using ::std::placeholders::_2; |
| 100 | using ::std::placeholders::_3; |
| 101 | using ::std::placeholders::_4; |
| 102 | using ::std::placeholders::_5; |
| 103 | using ::std::placeholders::_6; |
| 104 | } // apache::thrift::stdcxx::placeholders |
| 105 | }}} // apache::thrift::stdcxx |
| 106 | |
| 107 | #elif _THRIFT_USING_GNU_LIBSTDCXX |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 108 | #ifdef USE_BOOST_THREAD |
| 109 | #include <boost/tr1/functional.hpp> |
| 110 | #else |
| 111 | #include <tr1/functional> |
| 112 | #endif |
Roger Meier | 8252577 | 2012-11-16 00:38:27 +0000 | [diff] [blame] | 113 | |
| 114 | namespace apache { namespace thrift { namespace stdcxx { |
| 115 | using ::std::tr1::function; |
| 116 | using ::std::tr1::bind; |
| 117 | |
| 118 | namespace placeholders { |
| 119 | using ::std::tr1::placeholders::_1; |
| 120 | using ::std::tr1::placeholders::_2; |
| 121 | using ::std::tr1::placeholders::_3; |
| 122 | using ::std::tr1::placeholders::_4; |
| 123 | using ::std::tr1::placeholders::_5; |
| 124 | using ::std::tr1::placeholders::_6; |
| 125 | } // apache::thrift::stdcxx::placeholders |
| 126 | }}} // apache::thrift::stdcxx |
| 127 | #endif |
| 128 | |
Roger Meier | bb98ed4 | 2013-06-20 01:06:22 +0200 | [diff] [blame] | 129 | // Alias for thrift c++ compatibility namespace |
| 130 | namespace tcxx = apache::thrift::stdcxx; |
| 131 | |
Roger Meier | 8252577 | 2012-11-16 00:38:27 +0000 | [diff] [blame] | 132 | #endif // #ifndef _THRIFT_CXXFUNCTIONAL_H_ |