C++ просматривает join_with с использованием многосимвольного разделителяC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Гость
 C++ просматривает join_with с использованием многосимвольного разделителя

Сообщение Гость »


Можете ли вы использовать многосимвольную строку в качестве разделителя при использовании представлений C++23::join_with ?
gcc 14 возвращает сообщение об ошибке.

Код: Выделить всё

#include 
#include 
#include 
#include 
#include 
using namespace std;

int main(){
const string a[2]={"6", "7"};
const string buffer1 = a | views::join_with('\n') | ranges::to(); //OK
printf("%s", buffer1.c_str());

const string buffer2 = a | views::join_with(",\n") | ranges::to(); //KO
printf("%s", buffer2.c_str());
return 0;
}

Код: Выделить всё

prog.cc: In function 'int main()':
prog.cc:13:30: error: no match for 'operator|' (operand types are 'const std::string [2]' {aka 'const std::__cxx11::basic_string [2]'} and 'std::ranges::views::__adaptor::_Partial')
13 |     const string buffer2 = a | views::join_with(",\n") | ranges::to(); //KO
|                            ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~
|                            |                   |
|                            |                   std::ranges::views::__adaptor::_Partial
|                            const std::string [2] {aka const std::__cxx11::basic_string [2]}
In file included from prog.cc:5:
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:952:5: note: candidate: 'template  requires (__is_range_adaptor_closure) && (__adaptor_invocable) constexpr auto std::ranges::views::__adaptor::operator|(_Range&&, _Self&&)'
952 |     operator|(_Range&& __r, _Self&& __self)
|     ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:952:5: note:   template argument deduction/substitution failed:
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:952:5: note: constraints not satisfied
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges: In substitution of 'template  requires (__is_range_adaptor_closure) && (__adaptor_invocable) constexpr auto std::ranges::views::__adaptor::operator|(_Range&&, _Self&&) [with _Self = std::ranges::views::__adaptor::_Partial; _Range = const std::__cxx11::basic_string (&)[2]]':
prog.cc:13:54:   required from here
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:952:5: note:    13 |     const string buffer2 = a | views::join_with(",\n") | ranges::to(); //KO
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:952:5: note:       |                                                      ^
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:911:13:   required for the satisfaction of '__adaptor_invocable' [with _Self = std::ranges::views::__adaptor::_Partial; _Range = const std::__cxx11::basic_string (&)[2]]
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:912:9:   in requirements  [with _Adaptor = std::ranges::views::__adaptor::_Partial; _Args = {const std::__cxx11::basic_string (&)[2]}]
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:912:44: note: the required expression 'declval()((declval)()...)' is invalid
912 |       = requires { std::declval()(declval()...); };
|                    ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
cc1plus: note: set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:961:5: note: candidate: 'template  requires (__is_range_adaptor_closure) && (__is_range_adaptor_closure) constexpr auto std::ranges::views::__adaptor::operator|(_Lhs&&, _Rhs&&)'
961 |     operator|(_Lhs&& __lhs, _Rhs&& __rhs)
|     ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:961:5: note:   template argument deduction/substitution failed:
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:961:5: note: constraints not satisfied
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges: In substitution of 'template   requires (__is_range_adaptor_closure) && (__is_range_adaptor_closure) constexpr auto std::ranges::views::__adaptor::operator|(_Lhs&&, _Rhs&&) [with _Lhs = const std::__cxx11::basic_string (&)[2]; _Rhs = std::ranges::views::__adaptor::_Partial]':
prog.cc:13:54:   required from here
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:961:5: note:    13 |     const string buffer2 = a | views::join_with(",\n") | ranges::to(); //KO
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:961:5: note:       |                                                      ^
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:942:13:   required for the satisfaction of '__is_range_adaptor_closure' [with _Lhs = const std::__cxx11::basic_string (&)[2]]
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:943:9:   in requirements with '_Tp __t' [with _Tp = const std::__cxx11::basic_string (&)[2]]
/opt/wandbox/gcc-head/include/c++/14.0.1/ranges:943:70: note: the required expression 'std::ranges::views::__adaptor::__is_range_adaptor_closure_fn(__t, __t)' is invalid
943 |       = requires (_Tp __t) { __adaptor::__is_range_adaptor_closure_fn(__t, __t); };
|                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
In file included from /opt/wandbox/gcc-head/include/c++/14.0.1/format:44,
from prog.cc:1:
/opt/wandbox/gcc-head/include/c++/14.0.1/charconv:626:3: note: candidate: 'constexpr std::chars_format std::operator|(chars_format, chars_format)'
626 |   operator|(chars_format __lhs, chars_format __rhs) noexcept
|   ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/charconv:626:26: note:   no known conversion for argument 1 from 'const std::string [2]' {aka 'const std::__cxx11::basic_string [2]'} to 'std::chars_format'
626 |   operator|(chars_format __lhs, chars_format __rhs) noexcept
|             ~~~~~~~~~~~~~^~~~~
In file included from /opt/wandbox/gcc-head/include/c++/14.0.1/bits/memory_resource.h:38,
from /opt/wandbox/gcc-head/include/c++/14.0.1/string:67,
from /opt/wandbox/gcc-head/include/c++/14.0.1/bits/locale_classes.h:40,
from /opt/wandbox/gcc-head/include/c++/14.0.1/locale:41,
from /opt/wandbox/gcc-head/include/c++/14.0.1/format:47:
/opt/wandbox/gcc-head/include/c++/14.0.1/cstddef:136:3: note: candidate: 'constexpr std::byte std::operator|(byte, byte)'
136 |   operator|(byte __l, byte __r) noexcept
|   ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/cstddef:136:18: note:   no known conversion for argument 1 from 'const std::string [2]' {aka 'const std::__cxx11::basic_string [2]'} to 'std::byte'
136 |   operator|(byte __l, byte __r) noexcept
|             ~~~~~^~~
In file included from /opt/wandbox/gcc-head/include/c++/14.0.1/bits/locale_facets.h:43,
from /opt/wandbox/gcc-head/include/c++/14.0.1/locale:42:
/opt/wandbox/gcc-head/include/c++/14.0.1/bits/ios_base.h:87:3: note: candidate: 'constexpr std::_Ios_Fmtflags std::operator|(_Ios_Fmtflags, _Ios_Fmtflags)'
87 |   operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
|   ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/bits/ios_base.h:87:27: note:   no known conversion for argument 1 from 'const std::string [2]' {aka 'const std::__cxx11::basic_string [2]'} to 'std::_Ios_Fmtflags'
87 |   operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
|             ~~~~~~~~~~~~~~^~~
/opt/wandbox/gcc-head/include/c++/14.0.1/bits/ios_base.h:130:3: note: candidate: 'constexpr std::_Ios_Openmode std::operator|(_Ios_Openmode, _Ios_Openmode)'
130 |   operator|(_Ios_Openmode __a, _Ios_Openmode __b)
|   ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/bits/ios_base.h:130:27: note:   no known conversion for argument 1 from 'const std::string [2]' {aka 'const std::__cxx11::basic_string [2]'} to 'std::_Ios_Openmode'
130 |   operator|(_Ios_Openmode __a, _Ios_Openmode __b)
|             ~~~~~~~~~~~~~~^~~
/opt/wandbox/gcc-head/include/c++/14.0.1/bits/ios_base.h:170:3: note: candidate: 'constexpr std::_Ios_Iostate std::operator|(_Ios_Iostate, _Ios_Iostate)'
170 |   operator|(_Ios_Iostate __a, _Ios_Iostate __b)
|   ^~~~~~~~
/opt/wandbox/gcc-head/include/c++/14.0.1/bits/ios_base.h:170:26: note:   no known conversion for argument 1 from 'const std::string [2]' {aka 'const std::__cxx11::basic_string  [2]'} to 'std::_Ios_Iostate'
170 |   operator|(_Ios_Iostate __a, _Ios_Iostate __b)
|             ~~~~~~~~~~~~~^~~


Источник: https://stackoverflow.com/questions/780 ... -separator
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как разделить строку с помощью многосимвольного разделителя в C#?
    Гость » » в форуме C#
    0 Ответы
    27 Просмотры
    Последнее сообщение Гость
  • Как разделить строку с помощью многосимвольного разделителя в C#?
    Anonymous » » в форуме C#
    0 Ответы
    18 Просмотры
    Последнее сообщение Anonymous
  • Как разделить строку с помощью многосимвольного разделителя в C#?
    Anonymous » » в форуме C#
    0 Ответы
    23 Просмотры
    Последнее сообщение Anonymous
  • Почему g++ просматривает LIBRARY_PATH/../lib64 и где это описано?
    Anonymous » » в форуме C++
    0 Ответы
    18 Просмотры
    Последнее сообщение Anonymous
  • Почему maven не просматривает мою папку ~/.m2?
    Anonymous » » в форуме JAVA
    0 Ответы
    18 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C++»