boostorg / boostorg/metaparse

BOOST_METAPARSE_STRING_VALUE can be implemented without length limitation since C++17

Open
#19 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
48
Forks
35
PR merge metrics
No merged PRs in 30d

Description

We don't need to define `BOOST_METAPARSE_LIMIT_STRING_SIZE` macro anymore. Also I think compilation time will be reduced(haven't measured yet, but I believe).
```
#include

template struct fixed_string {
const CharT* data;
constexpr fixed_string(const CharT (&s)[N]) noexcept:
data{s} {
}
constexpr auto operator[](size_t i) const noexcept { return data[i]; }
constexpr size_t size() const noexcept { return N; }
};

template
fixed_string(const CharT(&)[N]) -> fixed_string;

template
struct convert_string {
template
static constexpr auto apply(std::index_sequence) noexcept {
return boost::metaparse::string{};
}
};

#define BOOST_METAPARSE_STRING_VALUE(S) ([]{ \
static constexpr fixed_string fs(S); \
return convert_string::apply(std::make_index_sequence{}); \
}())
```

The full snippet to play: https://godbolt.org/z/j117Karjq

Only one limitation - `BOOST_METAPARSE_STRING_VALUE` can't be used in `decltype` expressions:
```
decltype(BOOST_METAPARSE_STRING_VALUE("test")) a; // error: lambda-expression in unevaluated context only available with '-std=c++20' or '-std=gnu++20'
```
The workaround is to create temporary variable:
```
auto t = BOOST_METAPARSE_STRING_VALUE("test");
decltype(t) a; // OK
```

If it's interested, I can create PR.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.