File tree Expand file tree Collapse file tree 2 files changed +17
-15
lines changed
Platform.Collections/Stacks
Platform.Collections.Tests Expand file tree Collapse file tree 2 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Platform ::Collections::Tests
4
4
{
5
- struct EmptyStack : public Stacks ::IStack<int >
5
+ TEST (StackTests, Concept)
6
+ {
7
+ Stacks::CStack<int > auto stack = std::stack<int >{};
8
+ stack.push (1 );
9
+ ASSERT_EQ (stack.top (), 1 );
10
+ stack.pop ();
11
+ ASSERT_TRUE (stack.empty ());
12
+ }
13
+
14
+ struct EmptyStack : public Stacks ::IStack<int >
6
15
{
7
16
bool empty () const {}
8
17
@@ -15,22 +24,13 @@ namespace Platform::Collections::Tests
15
24
const int &top () const {}
16
25
};
17
26
18
- TEST (StackTests, Concept)
19
- {
20
- Stacks::CStack<int > auto stack = std::stack<int >{};
21
- stack.push (1 );
22
- ASSERT_EQ (stack.top (), 1 );
23
- stack.pop ();
24
- ASSERT_TRUE (stack.empty ());
25
- }
26
-
27
27
TEST (StackTests, Interface)
28
28
{
29
- std::unique_ptr<Stack ::IStack<int >> stack = std::make_unique<EmptyStack>();
29
+ std::unique_ptr<Stacks ::IStack<int >> stack = std::make_unique<EmptyStack>();
30
30
}
31
31
32
32
TEST (StackTests, ConceptInterface)
33
33
{
34
- Stacks::CStack<int > auto stack = EmptyStack{};
34
+ Stacks::CStack<int > auto stack = EmptyStack{};
35
35
}
36
36
}
Original file line number Diff line number Diff line change @@ -6,14 +6,16 @@ namespace Platform::Collections::Stacks
6
6
concept CStack = requires (TSelf& self, TElement item)
7
7
{
8
8
{ self.push (item) };
9
+
10
+ { self.pop () };
11
+
12
+ { self.top () } -> std::same_as<TElement&>;
9
13
}
10
14
&&
11
15
requires (const TSelf& self, TElement item)
12
16
{
13
17
{ self.empty () } -> std::same_as<bool >;
14
18
15
- { self.pop () };
16
-
17
- { self.top () } -> std::same_as<TElement&>;
19
+ { self.top () } -> std::same_as<const TElement&>;
18
20
};
19
21
}
You can’t perform that action at this time.
0 commit comments