A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/microsoft/STL/issues/3576 below:

`repeat_view`'s deduction guide doesn't handle 1 argument · Issue #3576 · microsoft/STL · GitHub

Found by @davidhunter22, analyzed by me, suggested fix by @CaseyCarter. We need to file an LWG issue with this proposed resolution.

WG21-N4928 [range.repeat.view] depicts repeat_view's constructors:

    constexpr explicit repeat_view(const T& value, Bound bound = Bound())
      requires copy_­constructible<T>;
    constexpr explicit repeat_view(T&& value, Bound bound = Bound());

and a deduction guide:

  template<class T, class Bound>
    repeat_view(T, Bound) -> repeat_view<T, Bound>;

This doesn't provide a deduction guide for 1 argument, even though the constructors can handle that.

Casey's suggested fix, slightly modified by me to match the Standardese instead of our implementation:

  template<class T, class Bound = unreachable_sentinel_t>
    repeat_view(T, Bound = Bound()) -> repeat_view<T, Bound>;

Full test case:

#include <iostream>
#include <ranges>

int main() {
    for (const auto& e : std::ranges::repeat_view("Hello", 2)) {
        std::cout << e << "\n";
    }
#ifdef USE_ONE_ARG
    // std::views::repeat also fails to compile. While it's more desirable in general,
    // std::ranges::repeat_view gives a clearer error message for this issue.
    for (const auto& e : std::ranges::repeat_view("Hello")) {
        std::cout << e << "\n";
    }
#endif
}
C:\Temp>cl /EHsc /nologo /W4 /MT /Od /std:c++latest meow.cpp && meow
meow.cpp
Hello
Hello

C:\Temp>cl /EHsc /nologo /W4 /MT /Od /std:c++latest /DUSE_ONE_ARG meow.cpp && meow
meow.cpp
meow.cpp(11): error C2641: cannot deduce template arguments for 'std::ranges::repeat_view'
meow.cpp(11): error C2893: Failed to specialize function template 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(const _Ty &,_Bo) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1543): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): note: With the following template arguments:
meow.cpp(11): note: '_Ty=char [6]'
meow.cpp(11): note: '_Bo=std::unreachable_sentinel_t'
meow.cpp(11): error C2780: 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(void)': expects 0 arguments - 1 provided
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1540): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): error C2780: 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(_Tuple &,std::integer_sequence<size_t,_Indices...>,_Bo) noexcept(<expr>)': expects 3 arguments - 1 provided
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1534): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): error C2784: 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(std::ranges::repeat_view<_Ty,_Bo>)': could not deduce template argument for 'std::ranges::repeat_view<_Ty,_Bo>' from 'const char [6]'
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1395): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): error C2530: 'e': references must be initialized
meow.cpp(11): error C3531: 'e': a symbol whose type contains 'auto' must have an initializer
meow.cpp(11): error C2143: syntax error: missing ';' before ':'
meow.cpp(11): error C2641: cannot deduce template arguments for 'std::ranges::repeat_view'
meow.cpp(11): error C2893: Failed to specialize function template 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(const _Ty &,_Bo) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1543): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): note: With the following template arguments:
meow.cpp(11): note: '_Ty=char [6]'
meow.cpp(11): note: '_Bo=std::unreachable_sentinel_t'
meow.cpp(11): error C2780: 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(void)': expects 0 arguments - 1 provided
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1540): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): error C2780: 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(_Tuple &,std::integer_sequence<size_t,_Indices...>,_Bo) noexcept(<expr>)': expects 3 arguments - 1 provided
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1534): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): error C2784: 'std::ranges::repeat_view<_Ty,_Bo> std::ranges::repeat_view(std::ranges::repeat_view<_Ty,_Bo>)': could not deduce template argument for 'std::ranges::repeat_view<_Ty,_Bo>' from 'const char [6]'
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1395): note: see declaration of 'std::ranges::repeat_view'
meow.cpp(11): error C2143: syntax error: missing ';' before ')'

C:\Temp>clang-cl /EHsc /nologo /W4 /MT /Od /std:c++latest /DUSE_ONE_ARG meow.cpp && meow
meow.cpp(11,26): error: no viable constructor or deduction guide for deduction of template arguments of 'repeat_view'
    for (const auto& e : std::ranges::repeat_view("Hello")) {
                         ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1543,44): note:
      candidate template ignored: substitution failure [with _Ty = char[6], _Bo = std::unreachable_sentinel_t]:
      constraints not satisfied for class template 'repeat_view' [with _Ty = char[6], _Bo = std::unreachable_sentinel_t]
        _NODISCARD_CTOR constexpr explicit repeat_view(const _Ty& _Value_, _Bo _Bound_ = _Bo{}) noexcept(
                                           ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1553,44): note:
      candidate template ignored: substitution failure [with _Ty = const char[6], _Bo = std::unreachable_sentinel_t]:
      constraints not satisfied for class template 'repeat_view' [with _Ty = const char[6], _Bo =
      std::unreachable_sentinel_t]
        _NODISCARD_CTOR constexpr explicit repeat_view(_Ty&& _Value_, _Bo _Bound_ = _Bo{}) noexcept(
                                           ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1395,11): note:
      candidate template ignored: could not match 'repeat_view<_Ty, _Bo>' against 'const char *'
    class repeat_view : public view_interface<repeat_view<_Ty, _Bo>> {
          ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1540,9): note: candidate
      function template not viable: requires 0 arguments, but 1 was provided
        repeat_view() requires default_initializable<_Ty> = default;
        ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1591,5): note: candidate
      function template not viable: requires 2 arguments, but 1 was provided
    repeat_view(_Ty, _Bo) -> repeat_view<_Ty, _Bo>;
    ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1534,35): note:
      candidate function template not viable: requires 3 arguments, but 1 was provided
        _NODISCARD_CTOR constexpr repeat_view(_Tuple& _Val, index_sequence<_Indices...>, _Bo _Bound_) noexcept(
                                  ^
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.36.32502\include\ranges(1565,44): note:
      candidate function template not viable: requires at least 2 arguments, but 1 was provided
        _NODISCARD_CTOR constexpr explicit repeat_view(piecewise_construct_t,
                                           ^
1 error generated.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4