mirror of
https://github.com/TartanLlama/optional.git
synced 2025-07-30 18:07:15 +02:00
Merge branch 'master' of github.com:TartanLlama/optional
This commit is contained in:
103
.travis.yml
103
.travis.yml
@ -1,5 +1,6 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
|
|
||||||
|
|
||||||
dist: trusty
|
dist: trusty
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
@ -11,8 +12,24 @@ matrix:
|
|||||||
sources:
|
sources:
|
||||||
- ubuntu-toolchain-r-test
|
- ubuntu-toolchain-r-test
|
||||||
packages:
|
packages:
|
||||||
- g++-5
|
- g++-6
|
||||||
env: COMPILER=g++-5 CXXSTD=11
|
env: COMPILER=g++-6 CXXSTD=11
|
||||||
|
- compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-7
|
||||||
|
env: COMPILER=g++-7 CXXSTD=11
|
||||||
|
- compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-8
|
||||||
|
env: COMPILER=g++-8 CXXSTD=11
|
||||||
- compiler: gcc
|
- compiler: gcc
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
@ -80,14 +97,61 @@ matrix:
|
|||||||
- clang++-3.9
|
- clang++-3.9
|
||||||
- libc++-dev
|
- libc++-dev
|
||||||
env: COMPILER=clang++-3.9 CXXSTD=11
|
env: COMPILER=clang++-3.9 CXXSTD=11
|
||||||
|
- compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-trusty-4.0
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang++-4.0
|
||||||
|
- libc++-dev
|
||||||
|
env: COMPILER=clang++-4.0 CXXSTD=11
|
||||||
|
- compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-trusty-5.0
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang++-5.0
|
||||||
|
- libc++-dev
|
||||||
|
env: COMPILER=clang++-5.0 CXXSTD=11
|
||||||
|
- compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-trusty-6.0
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang++-6.0
|
||||||
|
- libc++-dev
|
||||||
|
env: COMPILER=clang++-6.0 CXXSTD=11
|
||||||
|
|
||||||
- compiler: gcc
|
- compiler: gcc
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources:
|
sources:
|
||||||
- ubuntu-toolchain-r-test
|
- ubuntu-toolchain-r-test
|
||||||
packages:
|
packages:
|
||||||
- g++-5
|
- g++-6
|
||||||
env: COMPILER=g++-5 CXXSTD=14
|
env: COMPILER=g++-6 CXXSTD=14
|
||||||
|
- compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-7
|
||||||
|
env: COMPILER=g++-7 CXXSTD=14
|
||||||
|
- compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-8
|
||||||
|
env: COMPILER=g++-8 CXXSTD=14
|
||||||
- compiler: clang
|
- compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
@ -139,7 +203,36 @@ matrix:
|
|||||||
- clang++-3.9
|
- clang++-3.9
|
||||||
- libc++-dev
|
- libc++-dev
|
||||||
env: COMPILER=clang++-3.9 CXXSTD=14
|
env: COMPILER=clang++-3.9 CXXSTD=14
|
||||||
|
- compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-trusty-4.0
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang++-4.0
|
||||||
|
- libc++-dev
|
||||||
|
env: COMPILER=clang++-4.0 CXXSTD=14
|
||||||
|
- compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-trusty-5.0
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang++-5.0
|
||||||
|
- libc++-dev
|
||||||
|
env: COMPILER=clang++-5.0 CXXSTD=14
|
||||||
|
- compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-trusty-6.0
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang++-6.0
|
||||||
|
- libc++-dev
|
||||||
|
env: COMPILER=clang++-6.0 CXXSTD=14
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- if [ "$CXX" = "clang++" ]; then export CXX="$COMPILER -stdlib=libc++"; fi
|
- if [ "$CXX" = "clang++" ]; then export CXX="$COMPILER -stdlib=libc++"; fi
|
||||||
|
17
README.md
17
README.md
@ -90,21 +90,26 @@ o = j;
|
|||||||
|
|
||||||
Tested on:
|
Tested on:
|
||||||
|
|
||||||
- Linux CI
|
|
||||||
|
- Linux
|
||||||
|
* clang 6.0.1
|
||||||
|
* clang 5.0.2
|
||||||
|
* clang 4.0.1
|
||||||
* clang 3.9
|
* clang 3.9
|
||||||
* clang 3.8
|
* clang 3.8
|
||||||
* clang 3.7
|
* clang 3.7
|
||||||
* clang 3.6
|
* clang 3.6
|
||||||
* clang 3.5
|
* clang 3.5
|
||||||
* g++ 5.0
|
* g++ 8.0.1
|
||||||
|
* g++ 7.3
|
||||||
|
* g++ 6.4
|
||||||
* g++ 4.9
|
* g++ 4.9
|
||||||
* g++ 4.8
|
* g++ 4.8
|
||||||
- Windows CI
|
- Windows
|
||||||
* MSVC 2015
|
* MSVC 2015
|
||||||
* MSVC 2017
|
* MSVC 2017
|
||||||
- Linux manual
|
|
||||||
* g++ 7.2
|
Unfortunately GCC5.5 has a compiler bug which I have not worked around yet. All other GCC5 versions should work.
|
||||||
* g++ 5.4
|
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
|
@ -237,9 +237,14 @@ TEST_CASE("Monadic operations", "[monadic]") {
|
|||||||
REQUIRE(!o18r);
|
REQUIRE(!o18r);
|
||||||
|
|
||||||
const tl::optional<int> o19 = tl::nullopt;
|
const tl::optional<int> o19 = tl::nullopt;
|
||||||
auto o19r =
|
auto o19r = std::move(o19).and_then([](int i) { return tl::make_optional(42); });
|
||||||
std::move(o19).and_then([](int i) { return tl::make_optional(42); });
|
|
||||||
REQUIRE(!o19r);
|
REQUIRE(!o19r);
|
||||||
|
|
||||||
|
int i = 3;
|
||||||
|
tl::optional<int&> o20{i};
|
||||||
|
std::move(o20).and_then([](int& r){return tl::optional<int&>{++r};});
|
||||||
|
REQUIRE(o20);
|
||||||
|
REQUIRE(i == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("constexpr and_then") {
|
SECTION("constexpr and_then") {
|
||||||
|
@ -138,9 +138,9 @@ template <class F, class, class... Us> struct invoke_result_impl;
|
|||||||
|
|
||||||
template <class F, class... Us>
|
template <class F, class... Us>
|
||||||
struct invoke_result_impl<
|
struct invoke_result_impl<
|
||||||
F, decltype(invoke(std::declval<F>(), std::declval<Us>()...), void()),
|
F, decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
|
||||||
Us...> {
|
Us...> {
|
||||||
using type = decltype(invoke(std::declval<F>(), std::declval<Us>()...));
|
using type = decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class F, class... Us>
|
template <class F, class... Us>
|
||||||
@ -1707,11 +1707,11 @@ public:
|
|||||||
/// \group and_then
|
/// \group and_then
|
||||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) &&;
|
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) &&;
|
||||||
template <class F> TL_OPTIONAL_11_CONSTEXPR auto and_then(F &&f) && {
|
template <class F> TL_OPTIONAL_11_CONSTEXPR auto and_then(F &&f) && {
|
||||||
using result = detail::invoke_result_t<F, T &&>;
|
using result = detail::invoke_result_t<F, T &>;
|
||||||
static_assert(detail::is_optional<result>::value,
|
static_assert(detail::is_optional<result>::value,
|
||||||
"F must return an optional");
|
"F must return an optional");
|
||||||
|
|
||||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||||
: result(nullopt);
|
: result(nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1730,11 +1730,11 @@ public:
|
|||||||
/// \group and_then
|
/// \group and_then
|
||||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) const &&;
|
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) const &&;
|
||||||
template <class F> constexpr auto and_then(F &&f) const && {
|
template <class F> constexpr auto and_then(F &&f) const && {
|
||||||
using result = detail::invoke_result_t<F, const T &&>;
|
using result = detail::invoke_result_t<F, const T &>;
|
||||||
static_assert(detail::is_optional<result>::value,
|
static_assert(detail::is_optional<result>::value,
|
||||||
"F must return an optional");
|
"F must return an optional");
|
||||||
|
|
||||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||||
: result(nullopt);
|
: result(nullopt);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1762,12 +1762,12 @@ public:
|
|||||||
/// \group and_then
|
/// \group and_then
|
||||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) &&;
|
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) &&;
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t<F, T &&> and_then(F &&f) && {
|
TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t<F, T &> and_then(F &&f) && {
|
||||||
using result = detail::invoke_result_t<F, T &&>;
|
using result = detail::invoke_result_t<F, T &>;
|
||||||
static_assert(detail::is_optional<result>::value,
|
static_assert(detail::is_optional<result>::value,
|
||||||
"F must return an optional");
|
"F must return an optional");
|
||||||
|
|
||||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||||
: result(nullopt);
|
: result(nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1787,12 +1787,12 @@ public:
|
|||||||
/// \group and_then
|
/// \group and_then
|
||||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) const &&;
|
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) const &&;
|
||||||
template <class F>
|
template <class F>
|
||||||
constexpr detail::invoke_result_t<F, const T &&> and_then(F &&f) const && {
|
constexpr detail::invoke_result_t<F, const T &> and_then(F &&f) const && {
|
||||||
using result = detail::invoke_result_t<F, const T &&>;
|
using result = detail::invoke_result_t<F, const T &>;
|
||||||
static_assert(detail::is_optional<result>::value,
|
static_assert(detail::is_optional<result>::value,
|
||||||
"F must return an optional");
|
"F must return an optional");
|
||||||
|
|
||||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||||
: result(nullopt);
|
: result(nullopt);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user