Difference between revisions of "Used C++11 features"
From KlayGE
Gongminmin (Talk | contribs) |
Gongminmin (Talk | contribs) |
||
(20 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
Starting from [[KlayGE]] 4.2, some C++11 features are introduced to replace some [[Used boost libraries|features from Boost]]. [[KFL]] defines some macros based on compiler names and versions, to ensure which features are useable. Those macros are defined in KFL/Config.hpp. | Starting from [[KlayGE]] 4.2, some C++11 features are introduced to replace some [[Used boost libraries|features from Boost]]. [[KFL]] defines some macros based on compiler names and versions, to ensure which features are useable. Those macros are defined in KFL/Config.hpp. | ||
+ | |||
+ | Macros marked as ''italic'' is removed because all supported compilers have those features. | ||
== C++11 Core Language Features == | == C++11 Core Language Features == | ||
Line 5: | Line 7: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | ! Language Feature !! Macro !! MSVC !! GCC !! Alternative | + | ! Language Feature !! Macro !! MSVC !! GCC !! Clang !! Alternative |
|- | |- | ||
− | | Allowing move constructors to throw [noexcept] || KLAYGE_CXX11_CORE_NOEXCEPT_SUPPORT || | + | | Allowing move constructors to throw [noexcept] || KLAYGE_CXX11_CORE_NOEXCEPT_SUPPORT || {{Yes}}14.0 || {{Yes}}4.6 || {{Yes}}3.0 || throw() |
|- | |- | ||
− | | Declared type of an expression || KLAYGE_CXX11_CORE_DECLTYPE_SUPPORT || | + | | auto-typed variables, Multi-declarator auto, Declared type of an expression || ''KLAYGE_CXX11_CORE_DECLTYPE_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}2.9 || Boost.Typeof |
|- | |- | ||
− | | Extern templates || KLAYGE_CXX11_CORE_EXTERN_TEMPLATES_SUPPORT || | + | | Extern templates || ''KLAYGE_CXX11_CORE_EXTERN_TEMPLATES_SUPPORT'' || {{Yes}}9.0 || {{Yes}}4.3 || {{Yes}}2.9 || |
|- | |- | ||
− | | Explicit virtual overrides || KLAYGE_CXX11_CORE_OVERRIDE_SUPPORT || | + | | Explicit virtual overrides || ''KLAYGE_CXX11_CORE_OVERRIDE_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.7 || {{Yes}}3.0 || #define |
|- | |- | ||
− | | Generalized constant expressions || KLAYGE_CXX11_CORE_CONSTEXPR_SUPPORT || | + | | Generalized constant expressions || KLAYGE_CXX11_CORE_CONSTEXPR_SUPPORT || {{Yes}}14.0 || {{Yes}}4.6 || {{Yes}}3.1 || |
|- | |- | ||
− | | Null pointer constant || KLAYGE_CXX11_CORE_NULLPTR_SUPPORT || | + | | Null pointer constant || ''KLAYGE_CXX11_CORE_NULLPTR_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.6 || {{Yes}}3.0 || Self-implemented nullptr |
|- | |- | ||
− | | Range-based for || KLAYGE_CXX11_CORE_FOREACH_SUPPORT || | + | | Range-based for || ''KLAYGE_CXX11_CORE_FOREACH_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.6 || {{Yes}}3.0 || Boost.Foreach |
|- | |- | ||
− | | Rvalue references || KLAYGE_CXX11_CORE_RVALUE_REFERENCES_SUPPORT || | + | | Rvalue references || ''KLAYGE_CXX11_CORE_RVALUE_REFERENCES_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}2.9 || Boost.Move |
|- | |- | ||
− | | Static assertions || KLAYGE_CXX11_CORE_STATIC_ASSERT_SUPPORT || | + | | Static assertions || ''KLAYGE_CXX11_CORE_STATIC_ASSERT_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}2.9 || Boost.StaticAssert |
|- | |- | ||
− | | Strongly-typed enums || KLAYGE_CXX11_CORE_STRONGLY_TYPED_ENUMS_SUPPORT || | + | | Strongly-typed enums || ''KLAYGE_CXX11_CORE_STRONGLY_TYPED_ENUMS_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.4 || {{Yes}}2.9 || C++98 enum |
|- | |- | ||
− | | Variadic templates || KLAYGE_CXX11_CORE_VARIADIC_TEMPLATES || | + | | Variadic templates || ''KLAYGE_CXX11_CORE_VARIADIC_TEMPLATES'' || {{Yes}}12.0 || {{Yes}}4.3 || {{Yes}}2.9 || |
|} | |} | ||
Line 38: | Line 40: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | ! Name !! Macro !! MSVC !! GCC !! Alternative | + | ! Name !! Macro !! MSVC !! GCC !! Clang !! Alternative |
|- | |- | ||
− | | | + | | algorithm (only copy_if) || ''KLAYGE_CXX11_LIBRARY_ALGORITHM_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.3 || {{Yes}}3.0 || Self-implemented copy_if |
|- | |- | ||
− | | array || KLAYGE_CXX11_LIBRARY_ARRAY_SUPPORT || | + | | array || ''KLAYGE_CXX11_LIBRARY_ARRAY_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.Array |
|- | |- | ||
− | | atomic || KLAYGE_CXX11_LIBRARY_ATOMIC_SUPPORT || | + | | atomic || ''KLAYGE_CXX11_LIBRARY_ATOMIC_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.4 || {{Yes}}3.0 || Boost.Atomic |
|- | |- | ||
− | | chrono || KLAYGE_CXX11_LIBRARY_CHRONO_SUPPORT || | + | | chrono || ''KLAYGE_CXX11_LIBRARY_CHRONO_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.4 (Must have _GLIBCXX_HAS_GTHREADS) || {{Yes}}3.0 || Boost.Chrono |
|- | |- | ||
− | | cstdint || KLAYGE_CXX11_LIBRARY_CSTDINT_SUPPORT || | + | | cstdint || ''KLAYGE_CXX11_LIBRARY_CSTDINT_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.Integer |
|- | |- | ||
− | | | + | | emplace || ''KLAYGE_CXX11_LIBRARY_EMPLACE_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.8 || {{Yes}}3.0 || |
|- | |- | ||
− | | | + | | functional || ''KLAYGE_CXX11_LIBRARY_FUNCTIONAL_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.Functional |
|- | |- | ||
− | | | + | | mem_fn || ''KLAYGE_CXX11_LIBRARY_MEM_FN_SUPPORT'' || {{Yes}}12.0 || {{Yes}}4.8 || {{Yes}}3.4 || Boost.MemFn |
|- | |- | ||
− | | | + | | random || ''KLAYGE_CXX11_LIBRARY_RANDOM_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.Random |
|- | |- | ||
− | | | + | | regex || ''KLAYGE_CXX11_LIBRARY_REGEX_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.9 || {{Yes}}3.0 || Boost.Regex |
|- | |- | ||
− | | | + | | smart_ptr || ''KLAYGE_CXX11_LIBRARY_SMART_PTR_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.SmartPtr |
|- | |- | ||
− | | | + | | system_error || ''KLAYGE_CXX11_LIBRARY_SYSTEM_ERROR_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.4 || {{Yes}}3.0 || Boost.System |
|- | |- | ||
− | | | + | | thread || ''KLAYGE_CXX11_LIBRARY_THREAD_SUPPORT'' || {{Yes}}11.0 || {{Yes}}4.4 (Must have _GLIBCXX_HAS_GTHREADS) || {{Yes}}3.0 || Boost.Thread |
|- | |- | ||
− | | | + | | tuple || ''KLAYGE_CXX11_LIBRARY_TUPLE_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.Tuple |
|- | |- | ||
− | | | + | | type_traits || ''KLAYGE_CXX11_LIBRARY_TYPE_TRAITS_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.TypeTraits |
+ | |- | ||
+ | | unordered || ''KLAYGE_CXX11_LIBRARY_UNORDERED_SUPPORT'' || {{Yes}}10.0 || {{Yes}}4.3 || {{Yes}}3.0 || Boost.Unordered | ||
|} | |} | ||
− | == | + | == TS == |
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | ! Name !! Macro !! MSVC !! GCC !! Alternative | + | ! Name !! Macro !! MSVC !! GCC !! Clang !! Alternative |
|- | |- | ||
− | | filesystem || | + | | filesystem || KLAYGE_TS_LIBRARY_FILESYSTEM_V2_SUPPORT || {{Yes}}11.0 || {{No}}No || {{No}}No || Boost.FileSystem |
+ | |- | ||
+ | | filesystem || KLAYGE_TS_LIBRARY_FILESYSTEM_V3_SUPPORT || {{Yes}}14.0 || {{No}}No || {{No}}No || Boost.FileSystem | ||
+ | |- | ||
+ | | optional || KLAYGE_TS_LIBRARY_OPTIONAL_SUPPORT || {{No}}No || {{Yes}}4.9 || {{No}}No || Boost.Optional | ||
+ | |- | ||
+ | | any || KLAYGE_TS_LIBRARY_ANY_SUPPORT || {{No}}No || {{Yes}}5.1 || {{No}}No || Boost.Any | ||
|} | |} | ||
== See Also == | == See Also == | ||
[[C++11 support in compilers]] | [[C++11 support in compilers]] | ||
+ | |||
+ | [[Used boost libraries]] | ||
[[zh:使用到的C++11特性]] | [[zh:使用到的C++11特性]] |
Latest revision as of 02:35, 2 January 2017
Starting from KlayGE 4.2, some C++11 features are introduced to replace some features from Boost. KFL defines some macros based on compiler names and versions, to ensure which features are useable. Those macros are defined in KFL/Config.hpp.
Macros marked as italic is removed because all supported compilers have those features.
Contents
C++11 Core Language Features
Language Feature | Macro | MSVC | GCC | Clang | Alternative |
---|---|---|---|---|---|
Allowing move constructors to throw [noexcept] | KLAYGE_CXX11_CORE_NOEXCEPT_SUPPORT | 14.0 | 4.6 | 3.0 | throw() |
auto-typed variables, Multi-declarator auto, Declared type of an expression | KLAYGE_CXX11_CORE_DECLTYPE_SUPPORT | 10.0 | 4.3 | 2.9 | Boost.Typeof |
Extern templates | KLAYGE_CXX11_CORE_EXTERN_TEMPLATES_SUPPORT | 9.0 | 4.3 | 2.9 | |
Explicit virtual overrides | KLAYGE_CXX11_CORE_OVERRIDE_SUPPORT | 11.0 | 4.7 | 3.0 | #define |
Generalized constant expressions | KLAYGE_CXX11_CORE_CONSTEXPR_SUPPORT | 14.0 | 4.6 | 3.1 | |
Null pointer constant | KLAYGE_CXX11_CORE_NULLPTR_SUPPORT | 10.0 | 4.6 | 3.0 | Self-implemented nullptr |
Range-based for | KLAYGE_CXX11_CORE_FOREACH_SUPPORT | 11.0 | 4.6 | 3.0 | Boost.Foreach |
Rvalue references | KLAYGE_CXX11_CORE_RVALUE_REFERENCES_SUPPORT | 10.0 | 4.3 | 2.9 | Boost.Move |
Static assertions | KLAYGE_CXX11_CORE_STATIC_ASSERT_SUPPORT | 10.0 | 4.3 | 2.9 | Boost.StaticAssert |
Strongly-typed enums | KLAYGE_CXX11_CORE_STRONGLY_TYPED_ENUMS_SUPPORT | 11.0 | 4.4 | 2.9 | C++98 enum |
Variadic templates | KLAYGE_CXX11_CORE_VARIADIC_TEMPLATES | 12.0 | 4.3 | 2.9 |
C++11 Core Language Features: Concurrency
C++11 Core Language Features: C99
C++11 Libraries
Name | Macro | MSVC | GCC | Clang | Alternative |
---|---|---|---|---|---|
algorithm (only copy_if) | KLAYGE_CXX11_LIBRARY_ALGORITHM_SUPPORT | 11.0 | 4.3 | 3.0 | Self-implemented copy_if |
array | KLAYGE_CXX11_LIBRARY_ARRAY_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.Array |
atomic | KLAYGE_CXX11_LIBRARY_ATOMIC_SUPPORT | 11.0 | 4.4 | 3.0 | Boost.Atomic |
chrono | KLAYGE_CXX11_LIBRARY_CHRONO_SUPPORT | 11.0 | 4.4 (Must have _GLIBCXX_HAS_GTHREADS) | 3.0 | Boost.Chrono |
cstdint | KLAYGE_CXX11_LIBRARY_CSTDINT_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.Integer |
emplace | KLAYGE_CXX11_LIBRARY_EMPLACE_SUPPORT | 10.0 | 4.8 | 3.0 | |
functional | KLAYGE_CXX11_LIBRARY_FUNCTIONAL_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.Functional |
mem_fn | KLAYGE_CXX11_LIBRARY_MEM_FN_SUPPORT | 12.0 | 4.8 | 3.4 | Boost.MemFn |
random | KLAYGE_CXX11_LIBRARY_RANDOM_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.Random |
regex | KLAYGE_CXX11_LIBRARY_REGEX_SUPPORT | 10.0 | 4.9 | 3.0 | Boost.Regex |
smart_ptr | KLAYGE_CXX11_LIBRARY_SMART_PTR_SUPPORT | 11.0 | 4.3 | 3.0 | Boost.SmartPtr |
system_error | KLAYGE_CXX11_LIBRARY_SYSTEM_ERROR_SUPPORT | 10.0 | 4.4 | 3.0 | Boost.System |
thread | KLAYGE_CXX11_LIBRARY_THREAD_SUPPORT | 11.0 | 4.4 (Must have _GLIBCXX_HAS_GTHREADS) | 3.0 | Boost.Thread |
tuple | KLAYGE_CXX11_LIBRARY_TUPLE_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.Tuple |
type_traits | KLAYGE_CXX11_LIBRARY_TYPE_TRAITS_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.TypeTraits |
unordered | KLAYGE_CXX11_LIBRARY_UNORDERED_SUPPORT | 10.0 | 4.3 | 3.0 | Boost.Unordered |
TS
Name | Macro | MSVC | GCC | Clang | Alternative |
---|---|---|---|---|---|
filesystem | KLAYGE_TS_LIBRARY_FILESYSTEM_V2_SUPPORT | 11.0 | No | No | Boost.FileSystem |
filesystem | KLAYGE_TS_LIBRARY_FILESYSTEM_V3_SUPPORT | 14.0 | No | No | Boost.FileSystem |
optional | KLAYGE_TS_LIBRARY_OPTIONAL_SUPPORT | No | 4.9 | No | Boost.Optional |
any | KLAYGE_TS_LIBRARY_ANY_SUPPORT | No | 5.1 | No | Boost.Any |