-
Notifications
You must be signed in to change notification settings - Fork 34
Make BOOST_METAPARSE_STRING_VALUE unlimited in C++17 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
denzor200
wants to merge
3
commits into
boostorg:develop
Choose a base branch
from
denzor200:cxx17_string_value_
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #ifndef BOOST_METAPARSE_V1_CPP17_IMPL_CONVERT_STRING_HPP | ||
| #define BOOST_METAPARSE_V1_CPP17_IMPL_CONVERT_STRING_HPP | ||
|
|
||
| // Copyright Denis Mikhailov 2025. | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #include <boost/metaparse/v1/string.hpp> | ||
|
|
||
| #include <cstddef> // for std::size_t | ||
| #include <utility> // for std::make_index_sequence | ||
|
|
||
| namespace boost | ||
| { | ||
| namespace metaparse | ||
| { | ||
| namespace v1 | ||
| { | ||
| namespace impl | ||
| { | ||
| template<const auto& S> | ||
| struct convert_string { | ||
| template<std::size_t... Is> | ||
| static constexpr auto apply(std::index_sequence<Is...>) noexcept { | ||
| return ::boost::metaparse::v1::string<S[Is]...>{}; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #ifndef BOOST_METAPARSE_V1_CPP17_STRING_VALUE_HPP | ||
| #define BOOST_METAPARSE_V1_CPP17_STRING_VALUE_HPP | ||
|
|
||
| // Copyright Denis Mikhailov 2025. | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #include <boost/metaparse/v1/impl/fixed_string.hpp> | ||
| #include <boost/metaparse/v1/cpp17/impl/convert_string.hpp> | ||
|
|
||
| #include <utility> // for std::make_index_sequence | ||
|
|
||
| #ifdef BOOST_METAPARSE_V1_STRING_VALUE | ||
| #error BOOST_METAPARSE_V1_STRING_VALUE already defined | ||
| #endif | ||
|
|
||
| #define BOOST_METAPARSE_V1_STRING_VALUE(s) ([]{ \ | ||
| namespace impl = ::boost::metaparse::v1::impl; \ | ||
| static constexpr auto fs = impl::make_fixed_string(s); \ | ||
| return impl::convert_string<fs>::apply(std::make_index_sequence<fs.size() - 1>{}); \ | ||
| }()) | ||
|
|
||
| #endif | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #ifndef BOOST_METAPARSE_V1_IMPL_FIXED_STRING_HPP | ||
| #define BOOST_METAPARSE_V1_IMPL_FIXED_STRING_HPP | ||
|
|
||
| // Copyright Denis Mikhailov 2025. | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #include <cstddef> // for std::size_t | ||
|
|
||
| namespace boost | ||
| { | ||
| namespace metaparse | ||
| { | ||
| namespace v1 | ||
| { | ||
| namespace impl | ||
| { | ||
| template<typename CharT, std::size_t N> | ||
| struct fixed_string { | ||
| const CharT* data; | ||
| constexpr fixed_string(const CharT (&s)[N]) noexcept | ||
| : data{s} | ||
| {} | ||
| constexpr CharT operator[](std::size_t i) const noexcept { return data[i]; } | ||
| constexpr std::size_t size() const noexcept { return N; } | ||
| }; | ||
|
|
||
| template<typename CharT, std::size_t N> | ||
| constexpr fixed_string<CharT, N> make_fixed_string(const CharT(&s)[N]) noexcept { | ||
| return {s}; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright Denis Mikhailov 2025. | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #define BOOST_TEST_MODULE string_value_unlimited_cxx17 | ||
|
|
||
| #define BOOST_METAPARSE_LIMIT_STRING_SIZE 4 | ||
| #include <boost/metaparse/string.hpp> | ||
| #include <boost/metaparse/string_value.hpp> | ||
|
|
||
| #include <boost/test/unit_test.hpp> | ||
|
|
||
| #include <type_traits> | ||
|
|
||
| BOOST_AUTO_TEST_CASE(test_string_value_unlimited_cxx17) | ||
| { | ||
| auto abcde = BOOST_METAPARSE_STRING_VALUE("abcde"); | ||
|
|
||
| BOOST_MPL_ASSERT(( | ||
| std::is_same<boost::metaparse::string<'a', 'b', 'c', 'd', 'e'>, decltype(abcde)> | ||
| )); | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.