Skip to content

Commit 517d194

Browse files
committed
update flag library file
1 parent 26defa5 commit 517d194

File tree

2 files changed

+60
-33
lines changed

2 files changed

+60
-33
lines changed

tests/common.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
#include <probe/probe.hpp>
44
#include <flg/flags.hpp>
55

6-
namespace semantics_flags
6+
struct semantics_flags: flg::flags<int, semantics_flags>
77
{
8-
struct semantics_flags_tag{};
9-
using type = flg::flag<int, semantics_flags_tag>::type;
10-
11-
constexpr type None = type::none_flag();
12-
constexpr type NoConstruct = type::from_index(0);
13-
constexpr type NoCopy = type::from_index(1);
14-
constexpr type NoMove = type::from_index(2);
8+
constexpr static flag None = none_flag();
9+
constexpr static flag NoConstruct = from_index(0);
10+
constexpr static flag NoCopy = from_index(1);
11+
constexpr static flag NoMove = from_index(2);
1512
};
1613

1714
template <typename probe, typename functor>
18-
void verify_semantics(semantics_flags::type flags, functor f)
15+
void verify_semantics(semantics_flags flags, functor f)
1916
{
2017
probe::reset_counts();
2118

tests/lib/flg/flags.hpp

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,98 @@
33

44
namespace flg
55
{
6-
template <typename numeric_type, typename tag>
7-
struct flag
8-
{
9-
10-
struct type
6+
template <typename numeric_type, typename user_type>
7+
struct flags
118
{
129
using value_type = numeric_type;
1310

14-
explicit operator value_type() const { return value; }
15-
operator bool() const { return value; }
11+
explicit constexpr operator value_type() const { return value; }
12+
constexpr operator bool() const { return value; }
1613

17-
type operator~() const
14+
constexpr flags operator~() const
1815
{
19-
return type{~value};
16+
return flags{~value};
2017
}
21-
type operator&(type other) const
18+
constexpr flags operator&(flags other) const
2219
{
23-
return type{value & other.value};
20+
return flags{value & other.value};
2421
}
25-
type operator|(type other) const
22+
constexpr flags operator|(flags other) const
2623
{
27-
return type{value | other.value};
24+
return flags{value | other.value};
2825
}
29-
type operator^(type other) const
26+
constexpr flags operator^(flags other) const
3027
{
31-
return type{value ^ other.value};
28+
return flags{value ^ other.value};
3229
}
33-
type& operator&=(type other)
30+
constexpr flags& operator&=(flags other)
3431
{
3532
value &= other.value;
3633
return *this;
3734
}
38-
type& operator|=(type other)
35+
constexpr flags& operator|=(flags other)
3936
{
4037
value |= other.value;
4138
return *this;
4239
}
43-
type& operator^=(type other)
40+
constexpr flags& operator^=(flags other)
4441
{
4542
value ^= other.value;
4643
return *this;
4744
}
48-
bool operator==(type other) const
45+
constexpr bool operator==(flags other) const
4946
{
5047
return value == other.value;
5148
}
52-
bool operator!=(type other) const
49+
constexpr bool operator!=(flags other) const
5350
{
5451
return value != other.value;
5552
}
5653

5754
value_type value;
5855

59-
constexpr static type none_flag()
56+
struct flag
57+
{
58+
value_type value;
59+
60+
constexpr operator user_type() const
61+
{
62+
return user_type{value};
63+
}
64+
constexpr user_type operator~() const
65+
{
66+
return user_type{~value};
67+
}
68+
constexpr user_type operator&(flag other) const
69+
{
70+
return user_type{value & other.value};
71+
}
72+
constexpr user_type operator|(flag other) const
73+
{
74+
return user_type{value | other.value};
75+
}
76+
constexpr user_type operator^(flag other) const
77+
{
78+
return user_type{value ^ other.value};
79+
}
80+
constexpr bool operator==(flag other) const
81+
{
82+
return value == other.value;
83+
}
84+
constexpr bool operator!=(flag other) const
85+
{
86+
return value != other.value;
87+
}
88+
};
89+
90+
constexpr static flag none_flag()
6091
{
6192
return {0};
6293
}
63-
64-
constexpr static type from_index(value_type v)
94+
95+
constexpr static flag from_index(value_type v)
6596
{
6697
return {1 << v};
6798
}
6899
};
69-
};
70100
}

0 commit comments

Comments
 (0)