Das Beispiel, mit dem ich zu kämpfen habe und konvertieren diese in einzelne Wörter, senken Sie die Buchstaben, Entfernen von Nicht-Alphanumerikern aus diesem Satz und sortieren sie dann. Die ursprüngliche Beschreibung verwendete die Bereiche/V3 -Bibliothek und ich habe Probleme, dies ordnungsgemäß in C ++ 20 zu konvertieren. Insbesondere der anfängliche Teil, der sich mit der Erstellung eines Bereichs (oder einer Ansicht) auf Stdin befasst und diese dann an die nächste Transformation weitergibt. Ich versuche so etwas wie Folgendes zu verwenden: < /p>
Code: Select all
const std::vector words =
// Getting a range of words (tokens) from cin
std::views::istream(std::cin)
| views::transform(tolower) // Converting all words to lower-case
| views::transform(isalnum) // Removing non alphanumeric characters from the words
| views::filter([] (const std::string &s) {
return !s.empty();
})
| std::ranges::sort;
Code: Select all
main.cpp: In function ‘int main(int, char**)’:
main.cpp:38:9: error: no match for ‘operator|’ (operand types are ‘std::ranges::basic_istream_view’ and ‘std::ranges::views::__adaptor::_Partial’)
37 | std::views::istream(std::cin)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| std::ranges::basic_istream_view
38 | | views::transform(tolower) // Converting all words to lower-case
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| std::ranges::views::__adaptor::_Partial
In file included from main.cpp:7:
/usr/include/c++/13/ranges:896:7: note: candidate: ‘template requires (derived_from) && (derived_from) constexpr auto std::ranges::views::__adaptor::operator|(_Lhs, _Rhs)’
896 | operator|(_Lhs __lhs, _Rhs __rhs)
| ^~~~~~~~
/usr/include/c++/13/ranges:896:7: note: template argument deduction/substitution failed:
/usr/include/c++/13/ranges:896:7: note: constraints not satisfied
In file included from /usr/include/c++/13/compare:37,
from /usr/include/c++/13/bits/char_traits.h:56,
from /usr/include/c++/13/ios:42,
from /usr/include/c++/13/ostream:40,
from /usr/include/c++/13/iostream:41,
from main.cpp:1:
/usr/include/c++/13/concepts: In substitution of ‘template requires (derived_from) && (derived_from) constexpr auto std::ranges::views::__adaptor::operator|(_Lhs, _Rhs) [with _Lhs = std::ranges::basic_istream_view; _Rhs = std::ranges::views::__adaptor::_Partial]’:
main.cpp:38:35: required from here
/usr/include/c++/13/concepts:67:13: required for the satisfaction of ‘derived_from’ [with _Lhs = std::ranges::basic_istream_view]
/usr/include/c++/13/concepts:67:28: note: ‘std::ranges::views::__adaptor::_RangeAdaptorClosure’ is not a base of ‘std::ranges::basic_istream_view’
67 | concept derived_from = __is_base_of(_Base, _Derived)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/ranges:887:7: note: candidate: ‘template requires (derived_from) && (__adaptor_invocable) constexpr auto std::ranges::views::__adaptor::operator|(_Range&&, _Self&&)’
887 | operator|(_Range&& __r, _Self&& __self)
| ^~~~~~~~
/usr/include/c++/13/ranges:887:7: note: template argument deduction/substitution failed:
/usr/include/c++/13/ranges:887:7: note: constraints not satisfied
/usr/include/c++/13/ranges: In substitution of ‘template requires (derived_from) && (__adaptor_invocable) constexpr auto std::ranges::views::__adaptor::operator|(_Range&&, _Self&&) [with _Self = std::ranges::views::__adaptor::_Partial; _Range = std::ranges::basic_istream_view]’:
main.cpp:38:35: required from here
/usr/include/c++/13/ranges:859:13: required for the satisfaction of ‘__adaptor_invocable’ [with _Self = std::ranges::views::__adaptor::_Partial; _Range = std::ranges::basic_istream_view]
/usr/include/c++/13/ranges:860:9: in requirements [with _Adaptor = std::ranges::views::__adaptor::_Partial; _Args = {std::ranges::basic_istream_view}]
/usr/include/c++/13/ranges:860:44: note: the required expression ‘declval()((declval)()...)’ is invalid
860 | = requires { std::declval()(declval()...); };
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
cc1plus: note: set ‘-fconcepts-diagnostics-depth=’ to at least 2 for more detail
In file included from /usr/include/c++/13/bits/memory_resource.h:38,
from /usr/include/c++/13/string:58,
from /usr/include/c++/13/bits/locale_classes.h:40,
from /usr/include/c++/13/bits/ios_base.h:41,
from /usr/include/c++/13/ios:44:
/usr/include/c++/13/cstddef:135:3: note: candidate: ‘constexpr std::byte std::operator|(byte, byte)’
135 | operator|(byte __l, byte __r) noexcept
| ^~~~~~~~
/usr/include/c++/13/cstddef:135:18: note: no known conversion for argument 1 from ‘std::ranges::basic_istream_view’ to ‘std::byte’
135 | operator|(byte __l, byte __r) noexcept
| ~~~~~^~~
/usr/include/c++/13/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)
| ^~~~~~~~
/usr/include/c++/13/bits/ios_base.h:87:27: note: no known conversion for argument 1 from ‘std::ranges::basic_istream_view’ to ‘std::_Ios_Fmtflags’
87 | operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/13/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)
| ^~~~~~~~
/usr/include/c++/13/bits/ios_base.h:130:27: note: no known conversion for argument 1 from ‘std::ranges::basic_istream_view’ to ‘std::_Ios_Openmode’
130 | operator|(_Ios_Openmode __a, _Ios_Openmode __b)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/13/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)
| ^~~~~~~~
/usr/include/c++/13/bits/ios_base.h:170:26: note: no known conversion for argument 1 from ‘std::ranges::basic_istream_view’ to ‘std::_Ios_Iostate’
170 | operator|(_Ios_Iostate __a, _Ios_Iostate __b)
| ~~~~~~~~~~~~~^~~
< /code>
In typischer C ++ -Stoge ist dies sehr präzise und völlig unverständlich (für mich). Ich habe versucht, die anfängliche Reichweite auf verschiedene Weise zu erstellen, aber anscheinend lösen sie alle auf das gleiche zugrunde liegende std :: ranges :: Basic_istream_view
Anscheinend hat dieser Ansatz in der ursprünglichen Bereichen/V3 -Bibliothek (mit iStream_Range (std :: cin) ) funktioniert, funktioniert jedoch nicht in der aktuellen STD -Bibliothek.
Gibt es eine Möglichkeit, dies zum Laufen zu bringen?