]> git.lyx.org Git - lyx.git/commitdiff
Improve C++11 support
authorGeorg Baum <baum@lyx.org>
Sun, 21 Dec 2014 19:19:12 +0000 (20:19 +0100)
committerGeorg Baum <baum@lyx.org>
Sun, 21 Dec 2014 19:22:16 +0000 (20:22 +0100)
If we compile in C++11 mode, do not use the boost replacements for bind,
functional and shared_ptr. regex is excluded, since it misses match_partial, and
gcc does not provide a usable one in versions less than 4.9.0.
I also removed the #define for match_partial, since this is dangerous. Now you
get a compile error instead of subtle runtime differences.

CMakeLists.txt
configure.ac
src/support/bind.h
src/support/functional.h
src/support/regex.h
src/support/shared_ptr.h

index 0db64f7341842ad4d1df3ab60ad9e2ca180872f7..86f6a018069511b087faf8c5e823a8acbe50ab2d 100644 (file)
@@ -250,6 +250,8 @@ if(UNIX OR MINGW)
                set(LYX_USE_TR1 1)
                # GCC <= 4.5 does not support regex: there are linker errors
                # http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.tr1
+               # <regex> and <tr1/regex> in gcc are unusable in versions less than 4.9.0
+               # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
                set(LYX_USE_TR1_REGEX 0)
        endif()
        if (LYX_ENABLE_CXX11)
index 1cbb6bd978ab9d175a66f4aa29e2ed5d9c78588a..562eba4d9be4fc62c3c6c205bcc7b26f18146dcf 100644 (file)
@@ -285,6 +285,8 @@ char * strerror(int n);
 #define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1
 
 // TR1 regex not supported in GCC <= 4.5
+// <regex> and <tr1/regex> in gcc are unusable in versions less than 4.9.0
+// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
 // clang defines __GNUC__ but libc++ does not have tr1
 #ifndef LYX_USE_TR1
 #  if __GNUC__ == 4 && !defined(USE_LLVM_LIBCPP)
index efd3267de5ceb17667e94ed351b114d447ebf368..1931b163ec2f140a2ef7398031928a111811ebee 100644 (file)
 
 #ifdef LYX_USE_TR1
 
+#define LYX_BIND_NS std::tr1
+
 namespace lyx
 {
-       using std::tr1::bind;
        using std::tr1::placeholders::_1;
        using std::tr1::placeholders::_2;
-       using std::tr1::ref;
+}
+
+#elif __cplusplus >= 201103L
+
+#define LYX_BIND_NS std
+
+namespace lyx
+{
+       using std::placeholders::_1;
+       using std::placeholders::_2;
 }
 
 #else
 
 #include <boost/bind.hpp>
+#define LYX_BIND_NS boost
+
+#endif
 
 namespace lyx
 {
-       using boost::bind;
-       using boost::ref;
+       using LYX_BIND_NS::bind;
+       using LYX_BIND_NS::ref;
 }
 
-#endif
+#undef LYX_BIND_NS
 
 
 #endif
index 47d9c4596646169be53ff5b56a3f9625352b0891..bb60029611ec5c73b08c9202ee78819849c44645 100644 (file)
 #include <tr1/functional>
 #endif
 
-namespace lyx
-{
-       using std::tr1::function;
-}
+#define LYX_FUNCTIONAL_NS std::tr1
+
+#elif __cplusplus >= 201103L
+
+#include <functional>
+#define LYX_FUNCTIONAL_NS std
 
 #else
 
 #include <boost/function.hpp>
 #include <boost/functional.hpp>
+#define LYX_FUNCTIONAL_NS boost
+
+#endif
 
 namespace lyx
 {
-       using boost::function;
+       using LYX_FUNCTIONAL_NS::function;
 }
 
-#endif
+#undef LYX_FUNCTIONAL_NS
 
 
 #endif
index 96d6836e23cdd0e1387c63d5684c80ee0653461a..eb3b679a8053711877c9029c4e2937fdbf10f89a 100644 (file)
@@ -58,8 +58,7 @@ namespace lyx {
 }
 #  else
 #    include <tr1/regex>
-//   TODO no match_partial in gcc, how to replace?
-#    define match_partial match_default
+//   TODO no match_partial in TR1, how to replace?
 #  endif
 #  define LR_NS std::tr1
 namespace lyx {
@@ -67,6 +66,17 @@ using LR_NS::regex;
 using LR_NS::regex_match;
 using LR_NS::sregex_iterator;
 }
+#elif LYX_USE_TR1_REGEX
+#  include <regex>
+// <regex> in gcc is unusable in versions less than 4.9.0
+// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
+// TODO no match_partial in std, how to replace?
+#  define LR_NS std
+namespace lyx {
+using LR_NS::regex;
+using LR_NS::regex_match;
+using LR_NS::sregex_iterator;
+}
 #else 
 #  include <boost/regex.hpp>
 #  define LR_NS boost
index 69e42da23c216a96732d2a57c52772fee520df2e..874a6cde91d0b874d20b50bb4672c44e6fe19d42 100644 (file)
 #include <tr1/memory>
 #endif
 
-namespace lyx
-{
-       using std::tr1::shared_ptr;
-       using std::tr1::const_pointer_cast;
-}
+#define LYX_SHAREDPTR_NS std::tr1
+
+#elif __cplusplus >= 201103L
+
+#include <memory>
+#define LYX_SHAREDPTR_NS std
 
 #else
 
 #include <boost/shared_ptr.hpp>
+#define LYX_SHAREDPTR_NS boost
+
+#endif
 
 namespace lyx
 {
-       using boost::shared_ptr;
-       using boost::const_pointer_cast;
+       using LYX_SHAREDPTR_NS::shared_ptr;
+       using LYX_SHAREDPTR_NS::const_pointer_cast;
 }
 
-#endif
+#undef LYX_SHAREDPTR_NS
 
 
 #endif