PROTON-1527: [C++ binding] Bit more work on C++ auto feature selection
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/674d1e25 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/674d1e25 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/674d1e25 Branch: refs/heads/go1 Commit: 674d1e2511603b687f07df153b73114da129e1d5 Parents: ad665d2 Author: Andrew Stitcher <astitc...@apache.org> Authored: Wed Sep 27 03:02:07 2017 -0400 Committer: Andrew Stitcher <astitc...@apache.org> Committed: Tue Oct 10 16:28:03 2017 -0400 ---------------------------------------------------------------------- proton-c/bindings/cpp/cpp.cmake | 16 ++++----- .../bindings/cpp/include/proton/container.hpp | 2 +- .../bindings/cpp/include/proton/endpoint.hpp | 4 +-- .../cpp/include/proton/error_condition.hpp | 4 +-- proton-c/bindings/cpp/include/proton/fwd.hpp | 6 ++-- .../cpp/include/proton/internal/config.hpp | 34 +++++++++----------- .../include/proton/internal/pn_unique_ptr.hpp | 2 +- .../cpp/include/proton/internal/type_traits.hpp | 2 +- .../bindings/cpp/include/proton/work_queue.hpp | 11 +++---- proton-c/bindings/cpp/src/codec_test.cpp | 2 +- proton-c/bindings/cpp/src/container.cpp | 2 +- .../bindings/cpp/src/include/scalar_test.hpp | 2 +- .../cpp/src/proactor_container_impl.cpp | 4 +-- proton-c/bindings/cpp/src/work_queue.cpp | 4 +-- 14 files changed, 45 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/cpp.cmake ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/cpp.cmake b/proton-c/bindings/cpp/cpp.cmake index 99136fa..e49ec9a 100644 --- a/proton-c/bindings/cpp/cpp.cmake +++ b/proton-c/bindings/cpp/cpp.cmake @@ -32,19 +32,19 @@ check_cxx_source_compiles("#if defined(__cplusplus) && __cplusplus >= 201103\nin # Don't need to check individual flags if compiler claims to be C++11 or later as they will be set automatically if (NOT CPP11) set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} ${CXX_WARNING_FLAGS}") - cxx_test("long long ll; int main(int, char**) { return 0; }" LONG_LONG) - cxx_test("#include <memory>\nstd::shared_ptr<int> i; int main(int, char**) { return 0; }" SHARED_PTR) - cxx_test("#include <memory>\nstd::unique_ptr<int> u; int main(int, char**) { return 0; }" UNIQUE_PTR) + cxx_test("long long ll; int main(int, char**) { return 0; }" LONG_LONG_TYPE) cxx_test("int* x = nullptr; int main(int, char**) { return 0; }" NULLPTR) cxx_test("#include <string>\nvoid blah(std::string&&) {} int main(int, char**) { blah(\"hello\"); return 0; }" RVALUE_REFERENCES) cxx_test("class x {explicit operator int(); }; int main(int, char**) { return 0; }" EXPLICIT_CONVERSIONS) - cxx_test("class x {x(x&&)=default; }; int main(int, char**) { return 0; }" DEFAULTED_FUNCTIONS) + cxx_test("class x {x()=default; }; int main(int, char**) { return 0; }" DEFAULTED_FUNCTIONS) + cxx_test("class x {x(x&&)=default; }; int main(int, char**) { return 0; }" DEFAULTED_MOVE_INITIALIZERS) cxx_test("class x {x()=delete; }; int main(int, char**) { return 0; }" DELETED_FUNCTIONS) cxx_test("struct x {x() {}}; int main(int, char**) { static thread_local x foo; return 0; }" THREAD_LOCAL) - cxx_test("#include <functional>\nstd::function<int(void)> f = [](){return 42;}; int main(int, char**) { return 0; }" STD_FUNCTION) - cxx_test("#include <functional>\nvoid f(int) {} int main(int, char**) { std::bind(f, 42); return 0; }" STD_BIND) - cxx_test("#include <chrono>\nint main(int, char**) { return 0; }" CHRONO) - cxx_test("#include <random>\nint main(int, char**) { return 0; }" RANDOM) + cxx_test("int main(int, char**) { int a=[](){return 42;}(); return a; }" LAMBDAS) + cxx_test("template <class... X> void x(X... a) {} int main(int, char**) { x(1); x(43, \"\"); return 0; }" VARIADIC_TEMPLATES) + + cxx_test("#include <random>\nint main(int, char**) { return 0; }" HEADER_RANDOM) + cxx_test("#include <memory>\nstd::unique_ptr<int> u; int main(int, char**) { return 0; }" STD_UNIQUE_PTR) cxx_test("#include <thread>\nstd::thread t; int main(int, char**) { return 0; }" STD_THREAD) cxx_test("#include <mutex>\nstd::mutex m; int main(int, char**) { return 0; }" STD_MUTEX) cxx_test("#include <atomic>\nstd::atomic<int> a; int main(int, char**) { return 0; }" STD_ATOMIC) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/container.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp index 72155ba..58a3737 100644 --- a/proton-c/bindings/cpp/include/proton/container.hpp +++ b/proton-c/bindings/cpp/include/proton/container.hpp @@ -308,7 +308,7 @@ class PN_CPP_CLASS_EXTERN container { /// @cond INTERNAL /// This is a hack to ensure that the C++03 version is declared /// only during the compilation of the library -#if PN_CPP_HAS_STD_FUNCTION && defined(qpid_proton_cpp_EXPORTS) +#if PN_CPP_HAS_LAMBDAS && defined(qpid_proton_cpp_EXPORTS) PN_CPP_EXTERN void schedule(duration dur, v03::work fn); #endif /// @endcond http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/endpoint.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/endpoint.hpp b/proton-c/bindings/cpp/include/proton/endpoint.hpp index 0192454..8fc3b27 100644 --- a/proton-c/bindings/cpp/include/proton/endpoint.hpp +++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp @@ -64,14 +64,14 @@ PN_CPP_CLASS_EXTERN endpoint { /// @see endpoint_lifecycle virtual void close(const error_condition&) = 0; -#if PN_CPP_HAS_DEFAULTED_FUNCTIONS +#if PN_CPP_HAS_DEFAULTED_FUNCTIONS && PN_CPP_HAS_DEFAULTED_MOVE_INITIALIZERS // Make everything explicit for C++11 compilers /// @cond INTERNAL endpoint() = default; endpoint& operator=(const endpoint&) = default; - endpoint& operator=(endpoint&&) = default; endpoint(const endpoint&) = default; + endpoint& operator=(endpoint&&) = default; endpoint(endpoint&&) = default; /// @endcond #endif http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/error_condition.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/error_condition.hpp b/proton-c/bindings/cpp/include/proton/error_condition.hpp index ac612f6..cbd6e09 100644 --- a/proton-c/bindings/cpp/include/proton/error_condition.hpp +++ b/proton-c/bindings/cpp/include/proton/error_condition.hpp @@ -57,11 +57,11 @@ class error_condition { /// description, and informational properties. PN_CPP_EXTERN error_condition(std::string name, std::string description, proton::value properties); -#if PN_CPP_HAS_DEFAULTED_FUNCTIONS +#if PN_CPP_HAS_DEFAULTED_FUNCTIONS && PN_CPP_HAS_DEFAULTED_MOVE_INITIALIZERS /// @cond INTERNAL error_condition(const error_condition&) = default; - error_condition(error_condition&&) = default; error_condition& operator=(const error_condition&) = default; + error_condition(error_condition&&) = default; error_condition& operator=(error_condition&&) = default; /// @endcond #endif http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/fwd.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/fwd.hpp b/proton-c/bindings/cpp/include/proton/fwd.hpp index c5d2ccf..642cfe2 100644 --- a/proton-c/bindings/cpp/include/proton/fwd.hpp +++ b/proton-c/bindings/cpp/include/proton/fwd.hpp @@ -62,11 +62,9 @@ class void_function0; class work_queue; namespace v03 { class work; } -#if PN_CPP_HAS_STD_FUNCTION -namespace v11 { class work; } -#endif -#if PN_CPP_HAS_STD_FUNCTION +#if PN_CPP_HAS_LAMBDAS +namespace v11 { class work; } using v11::work; #else using v03::work; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/internal/config.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/internal/config.hpp b/proton-c/bindings/cpp/include/proton/internal/config.hpp index e600f21..9af12c2 100644 --- a/proton-c/bindings/cpp/include/proton/internal/config.hpp +++ b/proton-c/bindings/cpp/include/proton/internal/config.hpp @@ -41,16 +41,8 @@ #endif #endif -#ifndef PN_CPP_HAS_SHARED_PTR -#define PN_CPP_HAS_SHARED_PTR PN_CPP_HAS_CPP11 -#endif - -#ifndef PN_CPP_HAS_UNIQUE_PTR -#define PN_CPP_HAS_UNIQUE_PTR PN_CPP_HAS_CPP11 -#endif - -#ifndef PN_CPP_HAS_LONG_LONG -#define PN_CPP_HAS_LONG_LONG PN_CPP_HAS_CPP11 +#ifndef PN_CPP_HAS_LONG_LONG_TYPE +#define PN_CPP_HAS_LONG_LONG_TYPE PN_CPP_HAS_CPP11 #endif #ifndef PN_CPP_HAS_NULLPTR @@ -79,6 +71,10 @@ #define PN_CPP_HAS_DEFAULTED_FUNCTIONS PN_CPP_HAS_CPP11 #endif +#ifndef PN_CPP_HAS_DEFAULTED_MOVE_INITIALIZERS +#define PN_CPP_HAS_DEFAULTED_MOVE_INITIALIZERS PN_CPP_HAS_CPP11 +#endif + #ifndef PN_CPP_HAS_DELETED_FUNCTIONS #define PN_CPP_HAS_DELETED_FUNCTIONS PN_CPP_HAS_CPP11 #endif @@ -87,20 +83,22 @@ #define PN_CPP_HAS_THREAD_LOCAL PN_CPP_HAS_CPP11 #endif -#ifndef PN_CPP_HAS_STD_FUNCTION -#define PN_CPP_HAS_STD_FUNCTION PN_CPP_HAS_CPP11 +#ifndef PN_CPP_HAS_VARIADIC_TEMPLATES +#define PN_CPP_HAS_VARIADIC_TEMPLATES PN_CPP_HAS_CPP11 #endif -#ifndef PN_CPP_HAS_STD_BIND -#define PN_CPP_HAS_STD_BIND PN_CPP_HAS_CPP11 +#ifndef PN_CPP_HAS_LAMBDAS +#define PN_CPP_HAS_LAMBDAS PN_CPP_HAS_CPP11 #endif -#ifndef PN_CPP_HAS_CHRONO -#define PN_CPP_HAS_CHRONO PN_CPP_HAS_CPP11 +// Library features + +#ifndef PN_CPP_HAS_HEADER_RANDOM +#define PN_CPP_HAS_HEADER_RANDOM PN_CPP_HAS_CPP11 #endif -#ifndef PN_CPP_HAS_RANDOM -#define PN_CPP_HAS_RANDOM PN_CPP_HAS_CPP11 +#ifndef PN_CPP_HAS_STD_UNIQUE_PTR +#define PN_CPP_HAS_STD_UNIQUE_PTR PN_CPP_HAS_CPP11 #endif #ifndef PN_CPP_HAS_STD_MUTEX http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp b/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp index a3416e5..e47fbaa 100644 --- a/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp +++ b/proton-c/bindings/cpp/include/proton/internal/pn_unique_ptr.hpp @@ -60,7 +60,7 @@ template <class T> class pn_unique_ptr { bool operator !() const { return !get(); } void swap(pn_unique_ptr& x) { std::swap(ptr_, x.ptr_); } -#if PN_CPP_HAS_UNIQUE_PTR +#if PN_CPP_HAS_STD_UNIQUE_PTR operator std::unique_ptr<T>() { T *p = ptr_; ptr_ = 0; return std::unique_ptr<T>(p); } #endif http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp b/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp index bd16d29..6dcf23c 100644 --- a/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp +++ b/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp @@ -72,7 +72,7 @@ template <> struct is_signed<signed short> : public true_type {}; template <> struct is_signed<signed int> : public true_type {}; template <> struct is_signed<signed long> : public true_type {}; -#if PN_CPP_HAS_LONG_LONG +#if PN_CPP_HAS_LONG_LONG_TYPE template <> struct is_integral<unsigned long long> : public true_type {}; template <> struct is_integral<signed long long> : public true_type {}; template <> struct is_signed<unsigned long long> : public false_type {}; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/include/proton/work_queue.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/work_queue.hpp b/proton-c/bindings/cpp/include/proton/work_queue.hpp index 09e3d97..cafe0cf 100644 --- a/proton-c/bindings/cpp/include/proton/work_queue.hpp +++ b/proton-c/bindings/cpp/include/proton/work_queue.hpp @@ -64,7 +64,7 @@ class work { }; } -#if PN_CPP_HAS_STD_FUNCTION +#if PN_CPP_HAS_LAMBDAS namespace v11 { class work { public: @@ -90,7 +90,7 @@ class work { } #endif -#if PN_CPP_HAS_STD_FUNCTION +#if PN_CPP_HAS_LAMBDAS using v11::work; #else using v03::work; @@ -140,7 +140,7 @@ class PN_CPP_CLASS_EXTERN work_queue { /// @cond INTERNAL /// This is a hack to ensure that the C++03 version is declared /// only during the compilation of the library -#if PN_CPP_HAS_STD_FUNCTION && defined(qpid_proton_cpp_EXPORTS) +#if PN_CPP_HAS_LAMBDAS && defined(qpid_proton_cpp_EXPORTS) PN_CPP_EXTERN bool add(v03::work fn); #endif /// @endcond @@ -158,7 +158,7 @@ class PN_CPP_CLASS_EXTERN work_queue { /// @cond INTERNAL /// This is a hack to ensure that the C++03 version is declared /// only during the compilation of the library -#if PN_CPP_HAS_STD_FUNCTION && defined(qpid_proton_cpp_EXPORTS) +#if PN_CPP_HAS_LAMBDAS && defined(qpid_proton_cpp_EXPORTS) PN_CPP_EXTERN void schedule(duration, v03::work fn); #endif /// @endcond @@ -178,7 +178,7 @@ class PN_CPP_CLASS_EXTERN work_queue { // Utilities to make injecting functions/member functions palatable in C++03 // Lots of repetition to handle functions with up to 3 arguments -#if !PN_CPP_HAS_CPP11 +#if !PN_CPP_HAS_LAMBDAS template <class R> struct work0 : public proton::void_function0 { R (* fn_)(); @@ -402,7 +402,6 @@ void schedule_work(WQ wq, duration dn, F f, A a, B b, C c, D d) { wq->schedule(dn, make_work(f, a, b, c, d)); } -/// This version of proton::schedule_work schedule_works calling a free function to an arbitrary work queue #else // The C++11 version is *much* simpler and even so more general! // These definitions encompass everything in the C++03 section http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/src/codec_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/codec_test.cpp b/proton-c/bindings/cpp/src/codec_test.cpp index 7791749..df89dc3 100644 --- a/proton-c/bindings/cpp/src/codec_test.cpp +++ b/proton-c/bindings/cpp/src/codec_test.cpp @@ -90,7 +90,7 @@ int main(int, char**) { RUN_TEST(failed, simple_type_test(static_cast<unsigned int>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned long>(42))); -#if PN_CPP_HAS_LONG_LONG +#if PN_CPP_HAS_LONG_LONG_TYPE RUN_TEST(failed, simple_type_test(static_cast<long>(42))); RUN_TEST(failed, simple_type_test(static_cast<signed long>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned long>(42))); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/src/container.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/container.cpp b/proton-c/bindings/cpp/src/container.cpp index 0da852c..2641daa 100644 --- a/proton-c/bindings/cpp/src/container.cpp +++ b/proton-c/bindings/cpp/src/container.cpp @@ -112,7 +112,7 @@ returned<receiver> container::open_receiver( std::string container::id() const { return impl_->id(); } void container::schedule(duration d, v03::work f) { return impl_->schedule(d, f); } -#if PN_CPP_HAS_STD_FUNCTION +#if PN_CPP_HAS_LAMBDAS void container::schedule(duration d, v11::work f) { return impl_->schedule(d, f); } #endif http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/src/include/scalar_test.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/scalar_test.hpp b/proton-c/bindings/cpp/src/include/scalar_test.hpp index b075c98..a54eabe 100644 --- a/proton-c/bindings/cpp/src/include/scalar_test.hpp +++ b/proton-c/bindings/cpp/src/include/scalar_test.hpp @@ -193,7 +193,7 @@ template <class V> void scalar_test_group(int& failed) { RUN_TEST(failed, (simple_integral_test<V, unsigned short>())); RUN_TEST(failed, (simple_integral_test<V, unsigned int>())); RUN_TEST(failed, (simple_integral_test<V, unsigned long>())); -#if PN_CPP_HAS_LONG_LONG +#if PN_CPP_HAS_LONG_LONG_TYPE RUN_TEST(failed, (simple_integral_test<V, long long>())); RUN_TEST(failed, (simple_integral_test<V, unsigned long long>())); #endif http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/src/proactor_container_impl.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/proactor_container_impl.cpp b/proton-c/bindings/cpp/src/proactor_container_impl.cpp index 64c0f78..e83cc66 100644 --- a/proton-c/bindings/cpp/src/proactor_container_impl.cpp +++ b/proton-c/bindings/cpp/src/proactor_container_impl.cpp @@ -47,7 +47,7 @@ # include <thread> #endif -#if PN_CPP_HAS_RANDOM +#if PN_CPP_HAS_HEADER_RANDOM # include <random> #endif @@ -240,7 +240,7 @@ void container::impl::reconnect(pn_connection_t* pnc) { } namespace { -#if PN_CPP_HAS_RANDOM && PN_CPP_HAS_THREAD_LOCAL +#if PN_CPP_HAS_HEADER_RANDOM && PN_CPP_HAS_THREAD_LOCAL duration random_between(duration min, duration max) { static thread_local std::default_random_engine gen; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674d1e25/proton-c/bindings/cpp/src/work_queue.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/work_queue.cpp b/proton-c/bindings/cpp/src/work_queue.cpp index c8da7fb..acb3ae8 100644 --- a/proton-c/bindings/cpp/src/work_queue.cpp +++ b/proton-c/bindings/cpp/src/work_queue.cpp @@ -43,7 +43,7 @@ bool work_queue::add(v03::work f) { return impl_->add(f); } -#if PN_CPP_HAS_STD_FUNCTION +#if PN_CPP_HAS_LAMBDAS bool work_queue::add(v11::work f) { // If we have no actual work queue, then can't defer if (!impl_) return false; @@ -57,7 +57,7 @@ void work_queue::schedule(duration d, v03::work f) { return impl_->schedule(d, f); } -#if PN_CPP_HAS_STD_FUNCTION +#if PN_CPP_HAS_LAMBDAS void work_queue::schedule(duration d, v11::work f) { // If we have no actual work queue, then can't defer if (!impl_) return; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org