From f79c88c1906b14b59e19603fec93dba67844f3b4 Mon Sep 17 00:00:00 2001 From: Sergey Perepelitsa Date: Thu, 12 Feb 2015 23:34:40 +0300 Subject: [PATCH 1/7] Android.mk --- Android.mk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Android.mk diff --git a/Android.mk b/Android.mk new file mode 100644 index 00000000..c0ddd788 --- /dev/null +++ b/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE := cppformat_static +LOCAL_MODULE_FILENAME := libcppformat + +LOCAL_SRC_FILES := format.cc + +LOCAL_C_INCLUDES := $(LOCAL_PATH) +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) + +LOCAL_CFLAGS += -std=c++11 -fexceptions + +include $(BUILD_STATIC_LIBRARY) + +$(call import-module,.) From 2eef573656d40d397842f72ad02be2744222ec8f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 14 Feb 2015 23:22:14 +0800 Subject: [PATCH 2/7] Use explicitly deleted functions to make types non-copyable --- CMakeLists.txt | 11 +++++++++++ format.h | 13 ++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82843b2f..61af59c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,17 @@ endif () # add_definitions(-DFMT_USE_NOEXCEPT=1) #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 with clang. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) diff --git a/format.h b/format.h index 78a354f0..ca3eed91 100644 --- a/format.h +++ b/format.h @@ -121,9 +121,16 @@ // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class -#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const 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& operator=(const TypeName&) +#endif namespace fmt { From 43b9fefbd2dca012c20ffd043a4a9c6189582c82 Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 03:07:27 +0100 Subject: [PATCH 3/7] Use static_assert more actively --- CMakeLists.txt | 7 +++++++ posix.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61af59c9..2b29ed8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,13 @@ endif () # add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) #endif () +#check_cxx_source_compiles(" +# static_assert(true, \"\"); +# int main(){}" FMT_STATIC_ASSERT) +#if (FMT_STATIC_ASSERT) +# add_definitions(-DFMT_USE_STATIC_ASSERT=1) +#endif () + # GTest doesn't detect with clang. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) diff --git a/posix.h b/posix.h index 0f31f601..c8075cfb 100644 --- a/posix.h +++ b/posix.h @@ -68,7 +68,8 @@ # define FMT_UNUSED #endif -#if FMT_USE_STATIC_ASSERT +#if FMT_USE_STATIC_ASSERT || FMT_HAS_CPP_ATTRIBUTE(cxx_static_assert) || \ + (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600 # define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message) #else # define FMT_CONCAT_(a, b) FMT_CONCAT(a, b) From 9331533309bd2de4591c02ab86543a93c4bec34f Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 04:16:23 +0100 Subject: [PATCH 4/7] Use __GXX_EXPERIMENTAL_CXX0X__ for better C++11 detection --- format.h | 14 ++++++++++---- posix.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/format.h b/format.h index ca3eed91..03d4aa24 100644 --- a/format.h +++ b/format.h @@ -86,13 +86,19 @@ # define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif +#ifdef __GNUC__ +# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ +# define FMT_HAS_GXX_CXX11 1 +# endif +#endif + #ifndef FMT_USE_VARIADIC_TEMPLATES // Variadic templates are available in GCC since version 4.4 // (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++ // since version 2013. # define FMT_USE_VARIADIC_TEMPLATES \ (FMT_HAS_FEATURE(cxx_variadic_templates) || \ - (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || _MSC_VER >= 1800) + (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800) #endif #ifndef FMT_USE_RVALUE_REFERENCES @@ -103,7 +109,7 @@ # else # define FMT_USE_RVALUE_REFERENCES \ (FMT_HAS_FEATURE(cxx_rvalue_references) || \ - (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600) + (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600) # endif #endif @@ -113,7 +119,7 @@ // Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature). #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ - (FMT_GCC_VERSION >= 408 && __cplusplus >= 201103) + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) # define FMT_NOEXCEPT noexcept #else # define FMT_NOEXCEPT throw() @@ -122,7 +128,7 @@ // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \ - (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103L) || _MSC_VER >= 1800 + (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&) = delete; \ TypeName& operator=(const TypeName&) = delete diff --git a/posix.h b/posix.h index c8075cfb..a2cf2b13 100644 --- a/posix.h +++ b/posix.h @@ -69,7 +69,7 @@ #endif #if FMT_USE_STATIC_ASSERT || FMT_HAS_CPP_ATTRIBUTE(cxx_static_assert) || \ - (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600 + (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600 # define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message) #else # define FMT_CONCAT_(a, b) FMT_CONCAT(a, b) From 9fd566412d44c7f5da6245f1cb7e1a574d23a62e Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 Feb 2015 15:25:56 +0800 Subject: [PATCH 5/7] Refine --- format.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/format.h b/format.h index 03d4aa24..52e8d5b3 100644 --- a/format.h +++ b/format.h @@ -56,6 +56,9 @@ // many valid cases. # pragma GCC diagnostic ignored "-Wshadow" # endif +# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ +# define FMT_HAS_GXX_CXX11 1 +# endif #else # define FMT_GCC_EXTENSION #endif @@ -86,12 +89,6 @@ # define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif -#ifdef __GNUC__ -# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ -# define FMT_HAS_GXX_CXX11 1 -# endif -#endif - #ifndef FMT_USE_VARIADIC_TEMPLATES // Variadic templates are available in GCC since version 4.4 // (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++ From 1d49443405fc1f100df79a3302cad19d6f752699 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 15 Feb 2015 19:21:32 +0300 Subject: [PATCH 6/7] fix android.mk --- Android.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/Android.mk b/Android.mk index c0ddd788..db56d98d 100644 --- a/Android.mk +++ b/Android.mk @@ -13,4 +13,3 @@ LOCAL_CFLAGS += -std=c++11 -fexceptions include $(BUILD_STATIC_LIBRARY) -$(call import-module,.) From a85d5e962b58460f0cfc50b7998ce1c4ba8c889e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 15 Feb 2015 09:32:13 -0800 Subject: [PATCH 7/7] Update README.rst --- README.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index d3d6ef3b..7c5c86c4 100644 --- a/README.rst +++ b/README.rst @@ -238,9 +238,8 @@ Tinyformat This library supports printf-like format strings and is very small and fast. Unfortunately it doesn't support positional arguments and wrapping -it in C++98 is somewhat difficult. However if you only need a type-safe -printf replacement with support for user-defined types, I highly recommend -this library. +it in C++98 is somewhat difficult. Also its performance and code compactness +are limited by IOStreams. Boost Spirit.Karma ~~~~~~~~~~~~~~~~~~