Skip to content

Commit d85c365

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

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
5+
#include <ext/util/template_string_literal.hpp>
6+
7+
using namespace ext::util;
8+
9+
template<template_string_literal lit>
10+
struct example_class {
11+
const std::string name = lit.value;
12+
};
13+
14+
TEST(util_template_string_literal, error_to_string) {
15+
example_class<"foo"> actual;
16+
ASSERT_EQ(actual.name, "foo");
17+
}

0 commit comments

Comments
 (0)