aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/string/format_analyser.h
blob: 9a05e3eb8cf17f98a9fca1d785c06738f50c3416 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

#include <util/generic/strbuf.h>

#include <array>
#include <string_view>

namespace NYT::NDetail {

////////////////////////////////////////////////////////////////////////////////

struct TFormatAnalyser
{
public:
    template <class... TArgs>
    static consteval void ValidateFormat(std::string_view fmt);

private:
    // Non-constexpr function call will terminate compilation.
    // Purposefully undefined and non-constexpr/consteval
    template <class T>
    static void CrashCompilerNotFormattable(std::string_view /*msg*/)
    { /*Suppress "internal linkage but undefined" warning*/ }
    static void CrashCompilerNotEnoughArguments(std::string_view msg);
    static void CrashCompilerTooManyArguments(std::string_view msg);
    static void CrashCompilerWrongTermination(std::string_view msg);
    static void CrashCompilerMissingTermination(std::string_view msg);
    static void CrashCompilerWrongFlagSpecifier(std::string_view msg);

    struct TSpecifiers
    {
        std::string_view Conversion;
        std::string_view Flags;
    };
    template <class TArg>
    static consteval auto GetSpecifiers();

    static constexpr char IntroductorySymbol = '%';
};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NDetail

#define FORMAT_ANALYSER_INL_H_
#include "format_analyser-inl.h"
#undef FORMAT_ANALYSER_INL_H_