forked from TartanLlama/optional
Add emplace test
This commit is contained in:
@ -23,6 +23,7 @@ if(OPTIONAL_ENABLE_TESTS)
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/relops.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/relops.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/extensions.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/extensions.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/emplace.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/constexpr.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/constexpr.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
|
||||||
|
13
tests/emplace.cpp
Normal file
13
tests/emplace.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
|
#include "optional.hpp"
|
||||||
|
#include <utility>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
TEST_CASE("Emplace", "[emplace]") {
|
||||||
|
tl::optional<std::pair<std::pair<int,int>, std::pair<double, double>>> i;
|
||||||
|
i.emplace(std::piecewise_construct, std::make_tuple(0,2), std::make_tuple(3,4));
|
||||||
|
REQUIRE(i->first.first == 0);
|
||||||
|
REQUIRE(i->first.second == 2);
|
||||||
|
REQUIRE(i->second.first == 3);
|
||||||
|
REQUIRE(i->second.second == 4);
|
||||||
|
}
|
@ -1258,6 +1258,7 @@ public:
|
|||||||
|
|
||||||
*this = nullopt;
|
*this = nullopt;
|
||||||
this->construct(std::forward<Args>(args)...);
|
this->construct(std::forward<Args>(args)...);
|
||||||
|
return value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \group emplace
|
/// \group emplace
|
||||||
@ -1269,6 +1270,7 @@ public:
|
|||||||
emplace(std::initializer_list<U> il, Args &&... args) {
|
emplace(std::initializer_list<U> il, Args &&... args) {
|
||||||
*this = nullopt;
|
*this = nullopt;
|
||||||
this->construct(il, std::forward<Args>(args)...);
|
this->construct(il, std::forward<Args>(args)...);
|
||||||
|
return value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Swaps this optional with the other.
|
/// Swaps this optional with the other.
|
||||||
|
Reference in New Issue
Block a user