https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103924

            Bug ID: 103924
           Summary: views::join combined with std::string cannot be used
                    in constant expressions
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

The following code cannot be used as a constant expression, but it should work
since constexpr non-propagating-cache and std::string have been implemented.

#include <string>
#include <ranges>

int main() {
  using namespace std::string_literals;
  static_assert(std::ranges::distance(
      std::views::single("42"s) | std::views::join));
}

https://godbolt.org/z/zPv4xnxnP

#include <string>
#include <ranges>

int main() {
  using namespace std::string_literals;
  static_assert(std::ranges::distance(
      std::views::iota(0, 1) 
      | std::views::transform([](auto) { return "42"s; })
      | std::views::join));
}

https://godbolt.org/z/d5TM4x53z

Reply via email to