Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/boost/parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,14 @@ namespace boost { namespace parser {
constexpr bool is_range =
is_detected_v<has_begin, T> && is_detected_v<has_end, T>;

#if BOOST_PARSER_USE_CONCEPTS
template<typename T>
concept has_push_back = requires(T & t) { t.push_back(*t.begin()); };
#else
template<typename T>
using has_push_back =
decltype(std::declval<T &>().push_back(*std::declval<T>().begin()));
using has_push_back = decltype(
std::declval<T &>().push_back(*std::declval<T &>().begin()));
#endif

#if BOOST_PARSER_USE_CONCEPTS

Expand Down Expand Up @@ -1457,7 +1462,11 @@ namespace boost { namespace parser {
template<typename Container, typename T>
void insert(Container & c, T && x)
{
#if BOOST_PARSER_USE_CONCEPTS
if constexpr (has_push_back<Container>) {
#else
if constexpr (is_detected_v<has_push_back, Container>) {
#endif
c.push_back((T &&) x);
} else {
c.insert((T &&) x);
Expand Down
45 changes: 45 additions & 0 deletions test/compile_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,48 @@

using namespace boost::parser;

#if defined(__cpp_explicit_this_parameter)
# define BOOST_PARSER_TEST_EXPLICIT_THIS 1
#elif defined(__clang__)
# if __has_extension(cxx_explicit_this_parameter)
# define BOOST_PARSER_TEST_EXPLICIT_THIS 1
# endif
#endif

#if defined(BOOST_PARSER_TEST_EXPLICIT_THIS)
struct explicit_object_parameter_container
{
using iterator = int *;

iterator begin(this explicit_object_parameter_container & self)
{
return self.values_;
}
iterator end(this explicit_object_parameter_container & self)
{
return self.values_ + self.size_;
}
iterator insert(iterator pos, int value)
{
*pos = value;
return pos;
}
void push_back(this explicit_object_parameter_container & self, int value)
{
self.values_[self.size_++] = value;
}

int values_[4] = {};
int size_ = 0;
};

void compile_explicit_object_parameter_container()
{
explicit_object_parameter_container result;
parse("1 2", +int_, ws, result);
}
#endif

void compile_attribute_non_unicode()
{
// range
Expand Down Expand Up @@ -985,6 +1027,9 @@ void compile_attribute_sentinel()

void compile_attribute()
{
#if defined(BOOST_PARSER_TEST_EXPLICIT_THIS)
compile_explicit_object_parameter_container();
#endif
compile_attribute_non_unicode();
compile_attribute_unicode_utf8();
compile_attribute_unicode_utf32();
Expand Down