Skip to content

Commit

Permalink
Add more field count tests
Browse files Browse the repository at this point in the history
  • Loading branch information
runer112 committed Feb 10, 2023
1 parent 28bd7f5 commit e80f7aa
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 11 deletions.
16 changes: 16 additions & 0 deletions test/core/compile-fail/constructible_0+_args.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2023 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/pfr/tuple_size.hpp>

struct A
{
template <typename... Args>
explicit A(Args&&...) {}
};

int main() {
(void)boost::pfr::tuple_size<A>::value; // Must be a compile time error
}
16 changes: 16 additions & 0 deletions test/core/compile-fail/constructible_1+_args.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2023 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/pfr/tuple_size.hpp>

struct A
{
template <typename Arg0, typename... Args>
explicit A(Arg0&&, Args&&...) {}
};

int main() {
(void)boost::pfr::tuple_size<A>::value; // Must be a compile time error
}
91 changes: 80 additions & 11 deletions test/core/run/bitfields_count.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,90 @@
// Copyright (c) 2016-2022 Antony Polukhin
// Copyright (c) 2016-2023 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/pfr/tuple_size.hpp>

struct bf {
unsigned int i1: 1;
unsigned int i2: 1;
unsigned int i3: 1;
unsigned int i4: 1;
unsigned int i5: 1;
unsigned int i6: 1;
#include <cstdint>

struct bf7
{
uint8_t b0 : 1;
uint8_t b1 : 1;
uint8_t b2 : 1;
uint8_t b3 : 1;
uint8_t b4 : 1;
uint8_t b5 : 1;
uint8_t b6 : 1;
};
static_assert(sizeof(bf7) == 1, "");

int main() {
static_assert(boost::pfr::tuple_size<bf>::value == 6, "");
}
struct bf8
{
uint8_t b0 : 1;
uint8_t b1 : 1;
uint8_t b2 : 1;
uint8_t b3 : 1;
uint8_t b4 : 1;
uint8_t b5 : 1;
uint8_t b6 : 1;
uint8_t b7 : 1;
};
static_assert(sizeof(bf8) == 1, "");

struct bf16
{
uint8_t b0 : 1;
uint8_t b1 : 1;
uint8_t b2 : 1;
uint8_t b3 : 1;
uint8_t b4 : 1;
uint8_t b5 : 1;
uint8_t b6 : 1;
uint8_t b7 : 1;
uint8_t b8 : 1;
uint8_t b9 : 1;
uint8_t b10 : 1;
uint8_t b11 : 1;
uint8_t b12 : 1;
uint8_t b13 : 1;
uint8_t b14 : 1;
uint8_t b15 : 1;
};
static_assert(sizeof(bf16) == 2, "");

struct bf24
{
uint8_t b0 : 1;
uint8_t b1 : 1;
uint8_t b2 : 1;
uint8_t b3 : 1;
uint8_t b4 : 1;
uint8_t b5 : 1;
uint8_t b6 : 1;
uint8_t b7 : 1;
uint8_t b8 : 1;
uint8_t b9 : 1;
uint8_t b10 : 1;
uint8_t b11 : 1;
uint8_t b12 : 1;
uint8_t b13 : 1;
uint8_t b14 : 1;
uint8_t b15 : 1;
uint8_t b16 : 1;
uint8_t b17 : 1;
uint8_t b18 : 1;
uint8_t b19 : 1;
uint8_t b20 : 1;
uint8_t b21 : 1;
uint8_t b22 : 1;
uint8_t b23 : 1;
};
static_assert(sizeof(bf24) == 3, "");

int main() {
static_assert(boost::pfr::tuple_size_v<bf7> == 7, "");
static_assert(boost::pfr::tuple_size_v<bf8> == 8, "");
static_assert(boost::pfr::tuple_size_v<bf8> == 16, "");
static_assert(boost::pfr::tuple_size_v<bf24> == 24, "");
}

0 comments on commit e80f7aa

Please sign in to comment.