From 7df156b74ae11164eac8c8a5a992218e1b062974 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Mon, 24 Dec 2018 20:02:40 +0100 Subject: [PATCH 1/8] try fix --- test/cpp-utils/either_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index b5c0a8ce..2bd65af1 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -71,7 +71,8 @@ std::vector&)>> EXPECT_IS_LEFT(const Left }, [&] (auto& obj) { EXPECT_EQ(expected, obj.left_opt().value()); }, [&] (auto& obj) { - EXPECT_EQ(expected, std::move(obj).left_opt().value()); + auto a = std::move(obj).left_opt(); + EXPECT_EQ(expected, a.value()); }, [&] (auto& obj) { EXPECT_EQ(boost::none, obj.right_opt()); }, [&] (auto& obj) { From 9aa0dbfc198f5d4a755360532dfe3fd215b5c38d Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 07:43:41 +0100 Subject: [PATCH 2/8] try fix --- test/cpp-utils/either_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index 2bd65af1..6a208636 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -69,7 +69,8 @@ std::vector&)>> EXPECT_IS_LEFT(const Left }, [&] (auto& obj) { EXPECT_ANY_THROW(std::move(obj).right()); }, [&] (auto& obj) { - EXPECT_EQ(expected, obj.left_opt().value()); + auto a = obj.left_opt(); + EXPECT_EQ(expected, a.value()); }, [&] (auto& obj) { auto a = std::move(obj).left_opt(); EXPECT_EQ(expected, a.value()); From 70a25d2cb034bdd94ea5640131e263e60664997f Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 07:45:10 +0100 Subject: [PATCH 3/8] try fix --- test/cpp-utils/either_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index 6a208636..fb450130 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -98,9 +98,11 @@ std::vector&)>> EXPECT_IS_RIGHT(const Rig }, [&] (auto& obj) { EXPECT_ANY_THROW(std::move(obj).left()); }, [&] (auto& obj) { - EXPECT_EQ(expected, obj.right_opt().value()); + auto a = obj.right_opt(); + EXPECT_EQ(expected, a.value()); }, [&] (auto& obj) { - EXPECT_EQ(expected, std::move(obj).right_opt().value()); + auto a = std::move(obj).right_opt(); + EXPECT_EQ(expected, a.value()); }, [&] (auto& obj) { EXPECT_EQ(boost::none, obj.left_opt()); }, [&] (auto& obj) { From 621b0003948b34c9d8c98abb4855003a87fa5aa5 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 10:34:40 +0100 Subject: [PATCH 4/8] fix debug builds --- src/cpp-utils/either.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cpp-utils/either.h b/src/cpp-utils/either.h index d428294d..06c7d28d 100644 --- a/src/cpp-utils/either.h +++ b/src/cpp-utils/either.h @@ -80,7 +80,9 @@ namespace cpputils { } const Left &left() const& { - ASSERT(is_left(), "Tried to get left side of an either which is right."); + if (!is_left()) { + throw std::logic_error("Tried to get left side of an either which is right."); + } return _left; } Left &left() & { @@ -91,7 +93,9 @@ namespace cpputils { } const Right &right() const& { - ASSERT(is_right(), "Tried to get right side of an either which is left."); + if (!is_right()) { + throw std::logic_error("Tried to get right side of an either which is left."); + } return _right; } Right &right() & { From 2b21609190908ca1f27ab60c226dd5dda43e21d0 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 07:54:15 +0100 Subject: [PATCH 5/8] Upgrade to boost 1.58 --- .circleci/config.yml | 16 ++++++++-------- README.md | 2 +- cmake-utils/utils.cmake | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b45b568..f9194ef6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,12 +90,12 @@ references: restore_cache: keys: # Find the most recent cache from any branch - - v3_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} + - v4_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} upgrade_boost_post: &upgrade_boost_post save_cache: - key: v3_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} + key: v4_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} paths: - - /tmp/boost_1_57_0 + - /tmp/boost_1_58_0 upgrade_boost: &upgrade_boost run: name: Upgrade Boost @@ -104,10 +104,10 @@ references: export NUMCORES=`nproc` echo Using $NUMCORES cores # Download and prepare boost (only if not already present from cache) - if [ ! -d "/tmp/boost_1_57_0" ]; then + if [ ! -d "/tmp/boost_1_58_0" ]; then echo "Didn't find boost in cache. Downloading and building." - wget -O /tmp/boost.tar.bz2 https://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.tar.bz2/download - if [ $(sha512sum /tmp/boost.tar.bz2 | awk '{print $1;}') == "61881440fd89644c43c6e3bc6292e9fed75a6d3a76f98654b189d0ed4e1087d77b585884e882270c08bf9f7132b173bfc1fde05848e06aa78ba7f1008d10714d" ]; then + wget -O /tmp/boost.tar.bz2 https://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2/download + if [ $(sha512sum /tmp/boost.tar.bz2 | awk '{print $1;}') == "7480ec713b0aa13f0ec990603e87e3b5c8d53f4411329b10fae37fc963b90aad12dbd9290a33c3669ae801e9012a68683eadff057591e9ca2ebcd22b1a67b5d1" ]; then echo Correct sha512sum else echo Wrong sha512sum @@ -117,14 +117,14 @@ references: echo Extracting... tar -xf /tmp/boost.tar.bz2 -C /tmp rm -rf boost.tar.bz2 - cd /tmp/boost_1_57_0 + cd /tmp/boost_1_58_0 ./bootstrap.sh --with-toolset=${BUILD_TOOLSET} --with-libraries=filesystem,thread,chrono,program_options cd .. else echo Found boost in cache. Use cache and build. fi # Compile and install boost (if cached, this should be fast) - cd /tmp/boost_1_57_0 + cd /tmp/boost_1_58_0 sudo ./b2 toolset=${BUILD_TOOLSET} link=static cxxflags=-fPIC -d0 -j$NUMCORES install build_pre: &build_pre restore_cache: diff --git a/README.md b/README.md index fc2a26f0..58e6fa40 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Requirements - GCC version >= 5.0 or Clang >= 4.0 - CMake version >= 3.0 - libcurl4 (including development headers) - - Boost libraries version >= 1.57 (including development headers) + - Boost libraries version >= 1.58 (including development headers) - filesystem - system - chrono diff --git a/cmake-utils/utils.cmake b/cmake-utils/utils.cmake index 72cac168..6648871c 100644 --- a/cmake-utils/utils.cmake +++ b/cmake-utils/utils.cmake @@ -108,7 +108,7 @@ endfunction(target_enable_style_warnings) function(target_add_boost TARGET) # Load boost libraries if(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS) - # Many supported systems don't have boost >= 1.57. Better link it statically. + # Many supported systems don't have boost >= 1.58. Better link it statically. message(STATUS "Boost will be statically linked") set(Boost_USE_STATIC_LIBS ON) else(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS) @@ -116,7 +116,7 @@ function(target_add_boost TARGET) set(Boost_USE_STATIC_LIBS OFF) endif(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS) set(BOOST_THREAD_VERSION 4) - find_package(Boost 1.57.0 + find_package(Boost 1.58.0 REQUIRED COMPONENTS ${ARGN}) target_include_directories(${TARGET} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS}) From a81bbccf531d4d789e74d7e180f8afd7a56898f9 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 07:54:32 +0100 Subject: [PATCH 6/8] Change either_test to use optional correctly --- test/cpp-utils/either_test.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index fb450130..b5c0a8ce 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -69,11 +69,9 @@ std::vector&)>> EXPECT_IS_LEFT(const Left }, [&] (auto& obj) { EXPECT_ANY_THROW(std::move(obj).right()); }, [&] (auto& obj) { - auto a = obj.left_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, obj.left_opt().value()); }, [&] (auto& obj) { - auto a = std::move(obj).left_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, std::move(obj).left_opt().value()); }, [&] (auto& obj) { EXPECT_EQ(boost::none, obj.right_opt()); }, [&] (auto& obj) { @@ -98,11 +96,9 @@ std::vector&)>> EXPECT_IS_RIGHT(const Rig }, [&] (auto& obj) { EXPECT_ANY_THROW(std::move(obj).left()); }, [&] (auto& obj) { - auto a = obj.right_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, obj.right_opt().value()); }, [&] (auto& obj) { - auto a = std::move(obj).right_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, std::move(obj).right_opt().value()); }, [&] (auto& obj) { EXPECT_EQ(boost::none, obj.left_opt()); }, [&] (auto& obj) { From b2bcfce95a059e581813fd8fc786ce39ba780833 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Mon, 24 Dec 2018 18:34:42 +0100 Subject: [PATCH 7/8] More noexcept specifiers --- src/cpp-utils/either.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cpp-utils/either.h b/src/cpp-utils/either.h index 06c7d28d..b61eb649 100644 --- a/src/cpp-utils/either.h +++ b/src/cpp-utils/either.h @@ -12,13 +12,13 @@ namespace cpputils { class either final { public: template::value && !std::is_constructible::value>* = nullptr> - either(Head&& construct_left_head_arg, Tail&&... construct_left_tail_args) /* TODO noexcept(noexcept(std::declval>()._construct_left(std::forward(construct_left_head_arg), std::forward(construct_left_tail_args)...))) */ + either(Head&& construct_left_head_arg, Tail&&... construct_left_tail_args) noexcept(noexcept(std::declval>()._construct_left(std::forward(construct_left_head_arg), std::forward(construct_left_tail_args)...))) : _side(Side::left) { _construct_left(std::forward(construct_left_head_arg), std::forward(construct_left_tail_args)...); } template::value && std::is_constructible::value>* = nullptr> - either(Head&& construct_right_head_arg, Tail&&... construct_right_tail_args) /* TODO noexcept(noexcept(std::declval>()._construct_right(std::forward(construct_right_head_arg), std::forward(construct_right_tail_args)...))) */ + either(Head&& construct_right_head_arg, Tail&&... construct_right_tail_args) noexcept(noexcept(std::declval>()._construct_right(std::forward(construct_right_head_arg), std::forward(construct_right_tail_args)...))) : _side(Side::right) { _construct_right(std::forward(construct_right_head_arg), std::forward(construct_right_tail_args)...); } @@ -33,7 +33,7 @@ namespace cpputils { } } - either(either &&rhs) /* TODO noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) */ + either(either &&rhs) noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) : _side(rhs._side) { if(_side == Side::left) { _construct_left(std::move(rhs._left)); @@ -47,7 +47,7 @@ namespace cpputils { } //TODO Try allowing copy-assignment when Left/Right types are std::is_convertible - either &operator=(const either &rhs) /* TODO noexcept(noexcept(_construct_left(rhs._left)) && noexcept(_construct_right(rhs._right))) */ { + either &operator=(const either &rhs) noexcept(noexcept(_construct_left(rhs._left)) && noexcept(_construct_right(rhs._right))) { _destruct(); _side = rhs._side; if (_side == Side::left) { @@ -58,7 +58,7 @@ namespace cpputils { return *this; } - either &operator=(either &&rhs) /* TODO noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) */ { + either &operator=(either &&rhs) noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) { _destruct(); _side = rhs._side; if (_side == Side::left) { @@ -163,10 +163,10 @@ namespace cpputils { } template - friend either make_left(Args&&... args) /* TODO noexcept(noexcept(std::declval>()._construct_left(std::forward(args)...)))*/; + friend either make_left(Args&&... args) /* TODO noexcept(noexcept(std::declval>()._construct_left(std::forward(args)...))) */; template - friend either make_right(Args&&... args) /* TODO noexcept(noexcept(std::declval>()._construct_right(std::forward(args)...)))*/; + friend either make_right(Args&&... args) /* TODO noexcept(noexcept(std::declval>()._construct_right(std::forward(args)...))) */; }; template From 8f9dcad559123109dfa8f573af6e394e2b342f08 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 10:40:46 +0100 Subject: [PATCH 8/8] Re-enable light_opt()&& and left_opt()&& --- src/cpp-utils/either.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/cpp-utils/either.h b/src/cpp-utils/either.h index b61eb649..bca422a2 100644 --- a/src/cpp-utils/either.h +++ b/src/cpp-utils/either.h @@ -119,7 +119,15 @@ namespace cpputils { return boost::none; } } - // left_opt()&& not offered because optional doesn't work + // warning: opposed to the other left_opt variants, this one already moves the content and returns by value. + boost::optional left_opt() && noexcept(noexcept(boost::optional(std::move(_left)))) { + if (_side == Side::left) { + return std::move(_left); + } else { + return boost::none; + } + } + boost::optional right_opt() const& noexcept { if (_side == Side::right) { @@ -135,7 +143,16 @@ namespace cpputils { return boost::none; } } - // right_opt()&& not offered because optional doesn't work + // warning: opposed to the other left_opt variants, this one already moves the content and returns by value. + boost::optional right_opt() && noexcept(noexcept(boost::optional(std::move(_right)))) { + if (_side == Side::right) { + return std::move(_right); + } else { + return boost::none; + } + } + + private: union {