1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 20:24:26 +01:00

Add checks for std::chrono and std::function

This commit is contained in:
Matias Fontanini
2016-02-18 20:52:18 -08:00
parent 5c22cc7985
commit b326546229
5 changed files with 25 additions and 1 deletions

View File

@@ -74,7 +74,8 @@ OPTION(LIBTINS_ENABLE_CXX11 "Compile libtins with c++11 features" ON)
IF(LIBTINS_ENABLE_CXX11)
# We only use declval and decltype on gcc/clang as VC fails to build that code,
# at least on VC2013
IF(HAS_CXX11_RVALUE_REFERENCES AND ((HAS_CXX11_DECLVAL AND HAS_CXX11_DECLTYPE) OR MSVC))
IF(HAS_CXX11_RVALUE_REFERENCES AND HAS_CXX11_FUNCTIONAL AND HAS_CXX11_CHRONO AND
((HAS_CXX11_DECLVAL AND HAS_CXX11_DECLTYPE) OR MSVC))
SET(HAVE_CXX11 ON)
MESSAGE(STATUS "Enabling C++11 features")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")

View File

@@ -142,4 +142,6 @@ cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
cxx11_check_feature("declval" HAS_CXX11_DECLVAL)
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
cxx11_check_feature("functional" HAS_CXX11_FUNCTIONAL)
cxx11_check_feature("chrono" HAS_CXX11_CHRONO)
cxx11_check_feature("builtin-swap" HAS_GCC_BUILTIN_SWAP)

View File

@@ -0,0 +1,9 @@
#include <chrono>
using namespace std::chrono;
int main() {
system_clock::time_point tp = system_clock::now();
milliseconds ms = duration_cast<milliseconds>(tp.time_since_epoch());
return (ms.count() > 0) ? 0 : 1;
}

View File

@@ -0,0 +1,11 @@
#include <functional>
int add(int x, int y) {
return x + y;
}
int main() {
std::function<int(int, int)> func;
func = std::bind(&add, std::placeholders::_1, std::placeholders::_2);
return (func(2, 2) == 4) ? 0 : 1;
}

View File

@@ -40,6 +40,7 @@ using std::cerr;
using std::endl;
using std::bind;
using std::string;
using std::to_string;
using std::ostringstream;
using std::exception;