Skip to content

Commit

Permalink
[FIX] libc+++: missing braces for pod_tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Nov 17, 2023
1 parent 16eec9b commit e2bbb31
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 53 deletions.
15 changes: 12 additions & 3 deletions include/seqan3/utility/tuple/pod_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ struct pod_tuple
* actually enforces this on all types in the tuple (if you want to add non POD types, just use
* std::tuple instead).
*
* It (only) supports [aggregate initialization](https://en.cppreference.com/w/cpp/language/aggregate_initialization),
* i.e. you must use brace-initializiers and cannot
* use paranthesis. You can use seqan3::get or std::get and also
* You can use seqan3::get or std::get and also
* [structured bindings](https://en.cppreference.com/w/cpp/language/declarations#Structured_binding_declaration)
* to access the elements in the tuple.
*
Expand All @@ -57,6 +55,17 @@ struct pod_tuple<type0, types...>
type0 _head;
//!\brief The rest of the elements defined as a "recursive member".
pod_tuple<types...> _tail;

constexpr pod_tuple() noexcept = default; //!< Defaulted.
constexpr pod_tuple(pod_tuple const &) noexcept = default; //!< Defaulted.
constexpr pod_tuple & operator=(pod_tuple const &) noexcept = default; //!< Defaulted.
constexpr pod_tuple(pod_tuple &&) noexcept = default; //!< Defaulted.
constexpr pod_tuple & operator=(pod_tuple &&) noexcept = default; //!< Defaulted.
constexpr ~pod_tuple() noexcept = default; //!< Defaulted.

//!\brief Construct from arguments.
constexpr pod_tuple(type0 v0, types... args) noexcept : _head{v0}, _tail{args...}
{}
//!\endcond

/*!\name Comparison operators
Expand Down
105 changes: 55 additions & 50 deletions test/unit/utility/tuple/pod_tuple_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,66 @@

#include <type_traits>

#include <seqan3/utility/concept.hpp>
#include <seqan3/utility/tuple/pod_tuple.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-braces"
using tuple_t = seqan3::pod_tuple<int, long, float>;

TEST(pod_tuple, concepts)
{
EXPECT_TRUE(seqan3::trivial<tuple_t>);
EXPECT_TRUE(seqan3::standard_layout<tuple_t>);
}

// default/zero construction
TEST(pod_tuple_ctr, ctr)
TEST(pod_tuple, ctr)
{
[[maybe_unused]] seqan3::pod_tuple<int, long, float> t1;
[[maybe_unused]] tuple_t t1;
}

// aggregate initialization
TEST(pod_tuple_aggr, aggr)
TEST(pod_tuple, aggr)
{
[[maybe_unused]] seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
[[maybe_unused]] tuple_t t1{4, 7l, 3.0f};
[[maybe_unused]] tuple_t t2(4, 7l, 3.0f);
}

// zero initialization
TEST(pod_tuple_zro, zro)
TEST(pod_tuple, zro)
{
seqan3::pod_tuple<int, long, float> t1{0, 0, 0};
seqan3::pod_tuple<int, long, float> t2{};
tuple_t t1{0, 0, 0};
tuple_t t2{};

EXPECT_EQ(t1, t2);
}

// copy construction
TEST(pod_tuple_cp_ctr, cp_ctr)
TEST(pod_tuple, cp_ctr)
{
seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t2{t1};
seqan3::pod_tuple<int, long, float> t3(t1);
tuple_t t1{4, 7l, 3.0f};
tuple_t t2{t1};
tuple_t t3(t1);
EXPECT_EQ(t1, t2);
EXPECT_EQ(t2, t3);
}

// move construction
TEST(pod_tuple_mv_ctr, mv_ctr)
TEST(pod_tuple, mv_ctr)
{
seqan3::pod_tuple<int, long, float> t0{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t2{std::move(t1)};
tuple_t t0{4, 7l, 3.0f};
tuple_t t1{4, 7l, 3.0f};
tuple_t t2{std::move(t1)};
EXPECT_EQ(t2, t0);
seqan3::pod_tuple<int, long, float> t3(std::move(t2));
tuple_t t3(std::move(t2));
EXPECT_EQ(t3, t0);
}

// copy assignment
TEST(pod_tuple_cp_assgn, cp_assgn)
TEST(pod_tuple, cp_assgn)
{
seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t2;
seqan3::pod_tuple<int, long, float> t3;
tuple_t t1{4, 7l, 3.0f};
tuple_t t2;
tuple_t t3;

t2 = t1;
t3 = t1;
Expand All @@ -70,35 +77,35 @@ TEST(pod_tuple_cp_assgn, cp_assgn)
}

// move assignment
TEST(pod_tuple_mv_assgn, mv_assgn)
TEST(pod_tuple, mv_assgn)
{
seqan3::pod_tuple<int, long, float> t0{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t2;
seqan3::pod_tuple<int, long, float> t3;
tuple_t t0{4, 7l, 3.0f};
tuple_t t1{4, 7l, 3.0f};
tuple_t t2;
tuple_t t3;
t2 = std::move(t1);
EXPECT_EQ(t2, t0);
t3 = std::move(t2);
EXPECT_EQ(t3, t0);
}

// swap
TEST(pod_tuple_swap, swap)
TEST(pod_tuple, swap)
{
seqan3::pod_tuple<int, long, float> t0{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t2{};
seqan3::pod_tuple<int, long, float> t3{};
tuple_t t0{4, 7l, 3.0f};
tuple_t t1{4, 7l, 3.0f};
tuple_t t2{};
tuple_t t3{};

std::swap(t1, t2);
EXPECT_EQ(t2, t0);
EXPECT_EQ(t1, t3);
}

// get<1>
TEST(pod_tuple_get_i, get_i)
TEST(pod_tuple, get_i)
{
seqan3::pod_tuple<int, long, float> t0{4, 7l, 3.0f};
tuple_t t0{4, 7l, 3.0f};

static_assert(std::is_same_v<decltype(seqan3::get<0>(t0)), int &>);
static_assert(std::is_same_v<decltype(seqan3::get<1>(t0)), long &>);
Expand All @@ -111,7 +118,7 @@ TEST(pod_tuple_get_i, get_i)
// std::get<1>
TEST(pod_tuple, stdget_i)
{
seqan3::pod_tuple<int, long, float> t0{4, 7l, 3.0f};
tuple_t t0{4, 7l, 3.0f};

static_assert(std::is_same_v<decltype(std::get<0>(t0)), int &>);
static_assert(std::is_same_v<decltype(std::get<1>(t0)), long &>);
Expand All @@ -122,9 +129,9 @@ TEST(pod_tuple, stdget_i)
}

// structured bindings
TEST(pod_tuple_struct_binding, struct_binding)
TEST(pod_tuple, struct_binding)
{
seqan3::pod_tuple<int, long, float> t0{4, 7l, 3.0f};
tuple_t t0{4, 7l, 3.0f};
auto [i, l, f] = t0;

EXPECT_EQ(i, 4);
Expand All @@ -133,9 +140,9 @@ TEST(pod_tuple_struct_binding, struct_binding)
}

// get<type>
TEST(pod_tuple_get_type, get_type)
TEST(pod_tuple, get_type)
{
using pt = seqan3::pod_tuple<int, long, float>;
using pt = tuple_t;
using ptc = pt const;
pt t0{4, 7l, 3.0f};
ptc t1{4, 7l, 3.0f};
Expand Down Expand Up @@ -174,9 +181,9 @@ TEST(pod_tuple_get_type, get_type)
}

// std::get<type>
TEST(pod_tuple_get_type, stdget_type)
TEST(pod_tuple, stdget_type)
{
using pt = seqan3::pod_tuple<int, long, float>;
using pt = tuple_t;
using ptc = pt const;
pt t0{4, 7l, 3.0f};
ptc t1{4, 7l, 3.0f};
Expand Down Expand Up @@ -215,9 +222,9 @@ TEST(pod_tuple_get_type, stdget_type)
}

// std::tuple_element
TEST(pod_tuple_tuple_element, tuple_element)
TEST(pod_tuple, tuple_element)
{
using pt = seqan3::pod_tuple<int, long, float>;
using pt = tuple_t;

static_assert(std::is_same_v<std::tuple_element_t<0, pt>, int>);
static_assert(std::is_same_v<std::tuple_element_t<1, pt>, long>);
Expand All @@ -226,7 +233,7 @@ TEST(pod_tuple_tuple_element, tuple_element)
}

// type deduction
TEST(pod_tuple_type_deduce, type_deduce)
TEST(pod_tuple, type_deduce)
{
seqan3::pod_tuple t0{4, 7l, 3.0f};
using pt = decltype(t0);
Expand All @@ -237,11 +244,11 @@ TEST(pod_tuple_type_deduce, type_deduce)
}

// comparison operators
TEST(pod_tuple_cmp, cmp)
TEST(pod_tuple, cmp)
{
seqan3::pod_tuple<int, long, float> t0{4, 6l, 4.0f};
seqan3::pod_tuple<int, long, float> t1{4, 7l, 3.0f};
seqan3::pod_tuple<int, long, float> t2{4, 7l, 4.0f};
tuple_t t0{4, 6l, 4.0f};
tuple_t t1{4, 7l, 3.0f};
tuple_t t2{4, 7l, 4.0f};

EXPECT_LT(t0, t1);
EXPECT_LE(t0, t1);
Expand All @@ -251,5 +258,3 @@ TEST(pod_tuple_cmp, cmp)
EXPECT_GE(t2, t1);
EXPECT_GT(t2, t1);
}

#pragma GCC diagnostic pop

0 comments on commit e2bbb31

Please sign in to comment.