Skip to content

Commit 2bdb3d5

Browse files
committed
add: example of how to use template_string_literal
1 parent b878080 commit 2bdb3d5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

include/ext/util/template_string_literal.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66

77
namespace ext::util {
88

9+
// Usage:
10+
// template<template_string_literal lit>
11+
// struct example_class {
12+
// const std::string name = lit.value;
13+
// };
14+
915
// c++20 -- class types in non-type template parameters
16+
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0732r2.pdf
1017
template<std::size_t N>
1118
struct template_string_literal {
1219
constexpr template_string_literal(const char (&str)[N]) {

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(test-files
3939
"util_serialization"
4040
"util_show"
4141
"util_string"
42+
"util_template_string_literal"
4243
"util_tuple"
4344
"util_windows_strings"
4445
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright - 2020 - Jan Christoph Uhde <[email protected]>
2+
// Please see LICENSE.md for license or visit https://github.com/extcpp/basics
3+
#include <gtest/gtest.h>
4+
#include <ext/util/template_string_literal.hpp>
5+
6+
using namespace ext::util;
7+
8+
template<template_string_literal lit>
9+
struct example_class {
10+
const std::string name = lit.value;
11+
};
12+
13+
TEST(util_template_string_literal, example) {
14+
example_class<"foo"> actual;
15+
ASSERT_EQ(actual.name, "foo");
16+
}

0 commit comments

Comments
 (0)