43 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: std-at-least-c++2310 11// <ranges>12 13// [Example 1:14// vector<string> vs = {"the", "quick", "brown", "fox"};15// for (char c : vs | views::join_with('-')) {16// cout << c;17// }18// // The above prints the-quick-brown-fox19// - end example]20 21#include <ranges>22 23#include <cassert>24#include <string>25#include <vector>26 27constexpr bool test() {28 std::vector<std::string> vs = {"the", "quick", "brown", "fox"};29 std::string result;30 for (char c : vs | std::views::join_with('-')) {31 result += c;32 }33 34 return result == "the-quick-brown-fox";35}36 37int main(int, char**) {38 assert(test());39 static_assert(test());40 41 return 0;42}43