mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 22:59:47 +08:00
Fixed existing initializer_list member functions
Added additional initializer_list member functions
This commit is contained in:
parent
46b636694d
commit
8826b56493
@ -38,6 +38,7 @@ SOFTWARE.
|
||||
#include "error_handler.h"
|
||||
#include "utility.h"
|
||||
#include "variant.h"
|
||||
#include "initializer_list.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -353,6 +354,7 @@ namespace etl
|
||||
{
|
||||
}
|
||||
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
//*******************************************
|
||||
/// Construct value type from initializser_list and arguments.
|
||||
//*******************************************
|
||||
@ -361,6 +363,7 @@ namespace etl
|
||||
: storage(il, etl::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
//*******************************************
|
||||
/// Construct error type from arguments.
|
||||
@ -608,17 +611,23 @@ namespace etl
|
||||
template <typename... Args>
|
||||
ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
|
||||
{
|
||||
storage.emplace(etl::forward<Args>(args)...);
|
||||
storage.template emplace<value_type>(etl::forward<Args>(args)...);
|
||||
|
||||
return value();
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
///
|
||||
//*******************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
template <typename U, typename... Args>
|
||||
ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U>& il, Args&&... args) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
|
||||
{
|
||||
storage.emplace(il, etl::forward<Args>(args)...);
|
||||
storage.template emplace<value_type>(il, etl::forward<Args>(args)...);
|
||||
|
||||
return value();
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
//*******************************************
|
||||
///
|
||||
|
||||
@ -32,6 +32,7 @@ SOFTWARE.
|
||||
#include "etl/type_traits.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -441,6 +442,70 @@ namespace
|
||||
CHECK_EQUAL(input1.e, output2.e);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_emplace_from_initializer_list)
|
||||
{
|
||||
struct S
|
||||
{
|
||||
S()
|
||||
: vi()
|
||||
, a(0)
|
||||
, b(0)
|
||||
{
|
||||
}
|
||||
|
||||
S(std::initializer_list<int> il, int a_, int b_)
|
||||
: vi(il)
|
||||
, a(a_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<int> vi;
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
etl::expected<S, Error> exp;
|
||||
|
||||
S s1({ 10, 11, 12 }, 1, 2);
|
||||
S s2 = exp.emplace({ 10, 11, 12 }, 1, 2);
|
||||
|
||||
CHECK(s1.vi == s2.vi);
|
||||
CHECK_EQUAL(s1.a, s2.a);
|
||||
CHECK_EQUAL(s1.b, s2.b);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_emplace_from_vargs)
|
||||
{
|
||||
struct S
|
||||
{
|
||||
S()
|
||||
: a(0)
|
||||
, b(0)
|
||||
{
|
||||
}
|
||||
|
||||
S(int a_, int b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
etl::expected<S, Error> exp;
|
||||
|
||||
S s1(1, 2);
|
||||
S s2 = exp.emplace(1, 2);
|
||||
|
||||
CHECK_EQUAL(s1.a, s2.a);
|
||||
CHECK_EQUAL(s1.b, s2.b);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_move_construct_void_value)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user