Skip to content

Commit

Permalink
#959 Treat bitset with size_type
Browse files Browse the repository at this point in the history
  • Loading branch information
jwellbelove committed Nov 10, 2024
1 parent 4b7997a commit 36a5b4b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/etl/private/bitset_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ namespace etl

public:

typedef size_t size_type;

typedef typename etl::make_unsigned<ETL_BITSET_ELEMENT_TYPE>::type element_type;
typedef element_type element_t; // Backward compatibility

Expand Down
7 changes: 7 additions & 0 deletions include/etl/private/bitset_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ namespace etl
typedef TElement element_type;
typedef TElement* pointer;
typedef const TElement* const_pointer;
typedef size_t size_type;

static ETL_CONSTANT size_t npos = etl::integral_limits<size_t>::max;
static ETL_CONSTANT size_t Bits_Per_Element = etl::integral_limits<TElement>::bits;
Expand Down Expand Up @@ -1937,6 +1938,8 @@ namespace etl
typedef typename etl::private_bitset::bitset_common<Active_Bits, TElement>::span_type span_type;
typedef typename etl::private_bitset::bitset_common<Active_Bits, TElement>::const_span_type const_span_type;



using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
Expand Down Expand Up @@ -2826,6 +2829,8 @@ namespace etl
{
public:

typedef size_t size_type;

typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type;
typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type;
typedef etl::private_bitset::bitset_common<0U, unsigned char>::const_span_type const_span_type;
Expand All @@ -2850,6 +2855,8 @@ namespace etl

ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");

typedef size_t size_type;

typedef typename etl::private_bitset::bitset_common<Active_Bits, TElement>::element_type element_type;
typedef typename etl::private_bitset::bitset_common<Active_Bits, TElement>::span_type span_type;
typedef typename etl::private_bitset::bitset_common<Active_Bits, TElement>::const_span_type const_span_type;
Expand Down
8 changes: 8 additions & 0 deletions test/test_bitset_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,14 @@ namespace
CHECK_EQUAL("...*..*...**.*...*.*.**..****...", stdtext.c_str());
}

//*************************************************************************
TEST(test_global_size)
{
etl::bitset<32> b(0x12345678UL);

CHECK_EQUAL(32, ETL_OR_STD::size(b));
}

//*************************************************************************
TEST(test_issue_497_count_inverted_bits)
{
Expand Down
8 changes: 8 additions & 0 deletions test/test_bitset_new_default_element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,5 +2722,13 @@ namespace
CHECK_EQUAL(test_bit(6), t6);
CHECK_EQUAL(test_bit(7), t7);
}

//*************************************************************************
TEST(test_global_size)
{
etl::bitset<32> b(0x12345678UL);

CHECK_EQUAL(32, ETL_OR_STD::size(b));
}
};
}
8 changes: 8 additions & 0 deletions test/test_bitset_new_explicit_single_element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2815,5 +2815,13 @@ namespace
CHECK_EQUAL(test_bit(6), t6);
CHECK_EQUAL(test_bit(7), t7);
}

//*************************************************************************
TEST(test_global_size)
{
etl::bitset<32, uint32_t> b(0x12345678UL);

CHECK_EQUAL(32, ETL_OR_STD::size(b));
}
};
}
8 changes: 8 additions & 0 deletions test/test_bitset_new_ext_default_element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2471,5 +2471,13 @@ namespace
CHECK_EQUAL(test_bit(6), t6);
CHECK_EQUAL(test_bit(7), t7);
}

//*************************************************************************
TEST(test_global_size)
{
etl::bitset<32> b(0x12345678UL);

CHECK_EQUAL(32, ETL_OR_STD::size(b));
}
};
}
8 changes: 8 additions & 0 deletions test/test_bitset_new_ext_explicit_single_element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2619,5 +2619,13 @@ namespace
CHECK_EQUAL(test_bit(6), t6);
CHECK_EQUAL(test_bit(7), t7);
}

//*************************************************************************
TEST(test_global_size)
{
etl::bitset<32, uint32_t> b(0x12345678UL);

CHECK_EQUAL(32, ETL_OR_STD::size(b));
}
};
}

0 comments on commit 36a5b4b

Please sign in to comment.