sparrow 1.3.0
Loading...
Searching...
No Matches
fixed_string.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <algorithm>
18#include <cstddef>
19#include <string_view>
20
21namespace sparrow
22{
23 // Helper template to pass string literals as template parameters
24 template <std::size_t N>
26 {
27 constexpr fixed_string(const char (&str)[N])
28 {
29 std::copy_n(str, N, value);
30 }
31
32 constexpr operator std::string_view() const
33 {
34 return std::string_view(value, N - 1);
35 }
36
37 char value[N];
38 };
39}
constexpr fixed_string(const char(&str)[N])