Use explicitly deleted functions to make types non-copyable

This commit is contained in:
Carter Li 2015-02-14 23:22:14 +08:00
parent f77350f8fa
commit 2eef573656
2 changed files with 21 additions and 3 deletions

View File

@ -117,6 +117,17 @@ endif ()
# add_definitions(-DFMT_USE_NOEXCEPT=1) # add_definitions(-DFMT_USE_NOEXCEPT=1)
#endif () #endif ()
#check_cxx_source_compiles("
# struct C{
# C()=delete;
# C(const C&)=delete;
# C& operator=(const C&)=delete;
# };
# int main(){}" FMT_DELETED_FUNCTIONS)
#if (FMT_DELETED_FUNCTIONS)
# add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1)
#endif ()
# GTest doesn't detect <tuple> with clang. # GTest doesn't detect <tuple> with clang.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1)

View File

@ -121,9 +121,16 @@
// A macro to disallow the copy constructor and operator= functions // A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class // This should be used in the private: declarations for a class
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \
(FMT_GCC_VERSION >= 404 && __cplusplus >= 201103L) || _MSC_VER >= 1800
# define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
TypeName& operator=(const TypeName&) = delete
#else
# define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \ TypeName(const TypeName&); \
void operator=(const TypeName&) TypeName& operator=(const TypeName&)
#endif
namespace fmt { namespace fmt {