Skip to content

Commit

Permalink
[FixedStack/FixedQueue] Add tests for CTAD, ADL, usage in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkaratarakis committed Sep 30, 2023
1 parent 3455b28 commit c4d194f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/fixed_queue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,42 @@ TEST(FixedQueue, Full)
EXPECT_TRUE(is_full(v1));
}

TEST(FixedQueue, ClassTemplateArgumentDeduction)
{
// Compile-only test
FixedQueue a = FixedQueue<int, 5>{};
(void)a;
}

namespace
{
template <FixedQueue<int, 5> /*MY_QUEUE*/>
struct FixedQueueInstanceCanBeUsedAsATemplateParameter
{
};

template <FixedQueue<int, 5> /*MY_QUEUE*/>
constexpr void fixed_queue_instance_can_be_used_as_a_template_parameter()
{
}
} // namespace

TEST(FixedQueue, UsageAsTemplateParameter)
{
static constexpr FixedQueue<int, 5> QUEUE1{};
fixed_queue_instance_can_be_used_as_a_template_parameter<QUEUE1>();
FixedQueueInstanceCanBeUsedAsATemplateParameter<QUEUE1> my_struct{};
static_cast<void>(my_struct);
}

} // namespace fixed_containers

namespace another_namespace_unrelated_to_the_fixed_containers_namespace
{
TEST(FixedQueue, ArgumentDependentLookup)
{
// Compile-only test
fixed_containers::FixedQueue<int, 5> a{};
is_full(a);
}
} // namespace another_namespace_unrelated_to_the_fixed_containers_namespace
38 changes: 38 additions & 0 deletions test/fixed_stack_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,42 @@ TEST(FixedStack, Full)
EXPECT_TRUE(is_full(v1));
}

TEST(FixedStack, ClassTemplateArgumentDeduction)
{
// Compile-only test
FixedStack a = FixedStack<int, 5>{};
(void)a;
}

namespace
{
template <FixedStack<int, 5> /*MY_STACK*/>
struct FixedStackInstanceCanBeUsedAsATemplateParameter
{
};

template <FixedStack<int, 5> /*MY_STACK*/>
constexpr void fixed_stack_instance_can_be_used_as_a_template_parameter()
{
}
} // namespace

TEST(FixedStack, UsageAsTemplateParameter)
{
static constexpr FixedStack<int, 5> STACK1{};
fixed_stack_instance_can_be_used_as_a_template_parameter<STACK1>();
FixedStackInstanceCanBeUsedAsATemplateParameter<STACK1> my_struct{};
static_cast<void>(my_struct);
}

} // namespace fixed_containers

namespace another_namespace_unrelated_to_the_fixed_containers_namespace
{
TEST(FixedStack, ArgumentDependentLookup)
{
// Compile-only test
fixed_containers::FixedStack<int, 5> a{};
is_full(a);
}
} // namespace another_namespace_unrelated_to_the_fixed_containers_namespace

0 comments on commit c4d194f

Please sign in to comment.