Ranges that didn't make C++20

Related tags

Miscellaneous ranges
Overview

ranges

Implementations of ranges that didn't make C++20. Coded live on Twitch.

Documentation Status CMake

Types

tl::enumerate_view/tl::views::enumerate

A view which lets you iterate over the items in a range and their indices at the same time.

std::vector<int> v;
for (auto&& [index, item] : tl::views::enumerate(v)) {
  //...
}

tl::cycle_view/tl::views::cycle

Turns a view into an infinitely cycling one.

std::vector<int> v { 0, 1, 2 };
for (auto&& item : tl::views::cycle(v)) {
  std::cout << item << ' '; 
  //0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0...
}

tl::cartesian_product_view/tl::views::cartesian_product

A view representing the cartesian product of any number of other views.

std::vector<int> v { 0, 1, 2 };
for (auto&& [a,b,c] : tl::views::cartesian_product(v, v, v)) {
  std::cout << a << ' ' << b << ' ' << c << '\n';
  //0 0 0
  //0 0 1
  //0 0 2
  //0 1 0
  //0 1 1
  //...
}

Compiler Support

Tested on:

  • Visual Studio 2019 version 16.9
  • GCC 10.2

Next up

  • chunk

CC0

To the extent possible under law, Sy Brand has waived all copyright and related or neighboring rights to the optional library. This work is published from: United Kingdom.

Comments
  • Use two iterators (instead of N) to implement adjacent_view

    Use two iterators (instead of N) to implement adjacent_view

    read is still O(N), of course, but iterators are otherwise smaller and cheaper. Drive-by: merge pairs of end() and end() const overloads replacing concept overloading with if constexpr dispatch.

    opened by CaseyCarter 3
  • zip.hpp not compiling on clang

    zip.hpp not compiling on clang

    In Godbolt, I have imported zip.hpp (by manualling copy and pasting)

    https://godbolt.org/z/vrcaP6jbj

    Not compiling in clang :

    • error: missing 'typename' prior to dependent type name 'detail::tuple_or_pair_impl<Ts...>::type' using tuple_or_pair = detail::tuple_or_pair_impl<Ts...>::type;

    This may be related to another issue I have had using zip with std::view and it failing to compile (in MSCV) because of some indecipherable templating error

    opened by A-F-V 1
  • `transform_maybe` should cache `begin`

    `transform_maybe` should cache `begin`

    transform_maybe currently doesn't cache begin, and it could be that the begin is anywhere in the underlying range, so begin on our transform_maybe_view is not amortized constant time. It should cache begin.

    bug 
    opened by TartanLlama 1
  • Make view closures pipeable to each other

    Make view closures pipeable to each other

    This should compile:

    auto cycle_then_enumerate = tl::views::cycle | tl::views::enumerate;
    for (auto&& [i,e] : vec | cycle_then_enumerate) {
      //...
    }
    

    This should also compile:

    template <std::integral N>
    auto drop_then_enumerate(N n) {
      return tl::make_pipeable(std::drop(n)) | tl::enumerate;
    }
    
    enhancement 
    opened by TartanLlama 1
  • `cycle_view` should support non-common, sized, bidirectional ranges

    `cycle_view` should support non-common, sized, bidirectional ranges

    cycle_view currently requires bidirectional ranges to be common because it assigns std::ranges::end(base_) to current_ when it cycles from begin to end. Non-common, sized, bidirectional ranges should be supported.

    Range-v3 supports non-common, non-sized bidirectional ranges by --begin(my_cycle_view) being O(n) unless end has been cached. I don't think we should do that.

    enhancement 
    opened by TartanLlama 1
  • Compatibility issue between std::views::iota and tl::views::enumerate

    Compatibility issue between std::views::iota and tl::views::enumerate

    In the unit test below, a compilation error occurs.

    TEST_CASE("std::ranges::iota_view") {
        for (auto&& [i, j] : (std::views::iota(0) | tl::views::enumerate | std::views::take(10))) {
            REQUIRE(i == j);
        }
    }
    

    Error message:

    error C2678: binary '|': no operator found which takes a left-hand operand of type 'tl::enumerate_view<std::ranges::iota_view<_Ty,std::unreachable_sentinel_t>>' (or there is no acceptable conversion) with [ _Ty=int ]

    opened by naddu77 1
  • expected type-id as the default parameter for a type-parameter

    expected type-id as the default parameter for a type-parameter

    https://github.com/TartanLlama/ranges/blob/main/include/tl/to.hpp#L99

    Hi Sy, I'm trying to compile your code and have run up against this line. Is typename required before ContainerType's default type?

    template<int X>
    struct foo;
    
    template<int X, typename Y = foo<X>::type>
    struct bar;
    

    This is the same thing. It compiles with gcc and msvc but breaks with clang. Is this a context in which typename is relaxed for C++20, or is it a bug? Just asking so I can make the changes in my compiler if needed.

    http://eel.is/c++draft/temp.res#general-4.2.5

    I think this is a relaxed typename context, but it surprises me that clang trunk doesn't get this basic scenario right.

    opened by seanbaxter 1
  • Idempotent headers

    Idempotent headers

    Hi, Currenly the test programs include stuff before they include the header of the view they are testing I.E.

    #include <catch2/catch.hpp>
    #include <vector>
    #include <iostream>
    #include "tl/chunk.hpp"
    #include "tl/to.hpp"
    #include "tl/enumerate.hpp"
    

    in chunk.cpp. It would good to include the view you are testing first to make sure the header for that vierw is idempotent I.E

    #include "tl/chunk.hpp"  // Make sure this does not depend on things it does not include
    #include "tl/to.hpp"
    #include "tl/enumerate.hpp"
    #include <catch2/catch.hpp>
    #include <vector>
    #include <iostream>
    

    Let me know if you agree and I will create a pull request

    opened by davidhunter22 0
  • Factor out replicated can_reference concept to common.hpp

    Factor out replicated can_reference concept to common.hpp

    The can_reference concept was defined in both adjacent_transform and zip_transform.h. This factors this concept out and puts it in common.hpp

    Also added tl.h to include everything to check for similar, hopefully one day this will be a single module!

    opened by davidhunter22 0
  • Compilation error with zip_view

    Compilation error with zip_view

    Note I'm pretty new with ranges and concepts so I may be doing something dumb. This is with VS 17.1 Preview 2. I have used zip_view for a few things without problem. Removing the const in the vector and span makes the error go away.

    `void foo( ) { std::vector const ints { 0, 1, 2 }; std::span sp { ints };

    auto v { tl::zip_view( sp, ints ) };
    auto p { []( auto const& x ) -> bool { return true; } };
    
    // This does not compile with
    // 1>C:\Users\foo\source\repos\TL\ranges\src\ranges.cpp(18,18): error C2672: 'operator __surrogate_func': no matching overloaded function found
    // 1>C:\Users\foo\source\repos\TL\ranges\src\ranges.cpp(18,31): error C7602: 'std::ranges::_Any_of_fn::operator ()': the associated constraints are not satisfied
    std::ranges::any_of( v, p )
    

    };`

    zip_view.zip

    opened by davidhunter22 0
  • `chunk_by_key_view` should support input ranges

    `chunk_by_key_view` should support input ranges

    chunk_by_key_view currently supports forward ranges, because it's much easier. It can be made to support input ranges by having inner and outer cursors which communicate.

    enhancement 
    opened by TartanLlama 0
Owner
Sy Brand
@TartanLlama
Sy Brand
Single-header, ranges-compatible generator type built on C++20 coroutines

generator Single-header, ranges-compatible generator type built with C++20 coroutines. A generator allows implementing sequence producers which are te

Sy Brand 39 Dec 20, 2022
Companion source code for "Programming with C++20 - Concepts, Coroutines, Ranges, and more"

Companion Source Code for "Programming with C++20 - Concepts, Coroutines, Ranges, and more" 1. Edition Code examples This repository contains runnable

Andreas Fertig 162 Dec 31, 2022
Make screenshot every few minutes to make your small history!

Screenlapse Fun CPP application (which isn't well-made, can be optimized) that automatically make screenshots of your screen every few minutes and sto

raywave's junk projects 3 Aug 18, 2021
Some hypervisor research notes. There is also a useful exploit template that you can use to verify / falsify any assumptions you may make while auditing code, and for exploit development.

Introduction Over the past few weeks, I've been doing some hypervisor research here and there, with most of my focus being on PCI device emulation cod

Faith 130 Nov 18, 2022
A continuation of FSund's pteron-keyboard project. Feel free to contribute, or use these files to make your own! Kits and PCBs are also available through my facebook page.

pteron-pcb Intro This project is the evolution of the Pteron-Keyboard project, an incredible ergonomic keyboard that was handwired only. I aimed to in

null 17 Oct 11, 2022
C+- is a personal project trying to make a programming language.

C+- A personal project trying to be a programming language with close resemblence to C/C++ (probably gonna fail at that).

Arin 5 Nov 22, 2022
mimikatz is a tool I've made to learn C and make somes experiments with Windows security

mimikatz is a tool I've made to learn C and make somes experiments with Windows security

Benjamin DELPY 16.6k Dec 31, 2022
让Etwhook再次伟大! Make InfinityHook Great Again!

MakeInfinityHookGreatAgain Make InfinityHook Great Again 图片测试(2004系统两个小时): 怎么做 https://key08.com/index.php/2021/06/23/1170.html windows 20h1 x64 18个小时

Huoji's 99 Nov 19, 2022
sipeed opensource mechanical keyboard make with BL706

sipeed_keyboard sipeed opensource mechanical keyboard make with BL706 矽π 开源双模机械键盘 目录结构 ./ ├── LICENSE ├── README.md ├── firmware // 存放键盘固件 ├── hardwar

Sipeed 58 Dec 23, 2022
VinyGo is an open hardawe, meca, and source project to make a vinyl recorder.

The goal of this project is to refresh the gramophone concept to build a vinyl recorder, easier, more accessible, and affordable. Is made for artists, vinyl stores, recording studios, or music lovers.

null 10 Dec 16, 2022
Simple EFI runtime driver that hooks GetVariable function and returns data expected by Windows to make it think that it's running with secure boot enabled (faking secure boot)

SecureFakePkg is a simple EFI runtime driver that hooks GetVariable function and returns data expected by Windows to make it think that it's running with secure boot enabled. In other words, it fakes secure boot status.

Samuel Tulach 80 Dec 30, 2022
Fast unidirectional synchronization - make or efficiently update a copy of a database, without slow dumping & reloading

Fast unidirectional synchronization - make or efficiently update a copy of a database, without slow dumping & reloading

Will Bryant 267 Dec 23, 2022
ApeX is a static library for C++ software. Originally it was created to make C++ studying easier,

ApeX is a static library for C++ software. Originally it was created to make C++ studying easier, so it has functions to complete common tasks with just one line of code. But who knows, maybe this library will get bigger some day

null 0 Jan 18, 2022
kbuild is a build tool that works "like make" targetted at kernel/os development

kbuild : a kernel (and os) builder kbuild is a build tool that works "like make" targetted at kernel/os development Installing and building kbuild kbu

Valentin HAUDIQUET 1 Dec 11, 2021
a work in progress try to make an IDE with the CSFML

EatSleepCode A work in progress for educational purpose. To help better understanding the CSFML lib. Installation clone this repo and do make Use case

Saverio 1 Nov 20, 2022
Kernel source for j7y17lte - the goal is to make it as closest to linux-stable sources as possible without breaking OneUI compatibility.

Linux kernel release 3.x <http://kernel.org/> These are the release notes for Linux version 3. Read them carefully, as they tell you what this is al

Exynos7870 1 Oct 28, 2021
possibly the cheapest polysynth you can make

Arduino Polysynth possibly the cheapest polysynth you can make. It doesn't have an interface - you have to plug in a midi keyboard. It has 10 voices,

Marek Bereza 10 Jul 20, 2022
Make CVE-2020-0668 exploit work for version < win10 v1903 and version >= win10 v1903

CVE-2020-0668 Made CVE-2020-0668 exploit work for version < win10 v1903 and version >= win10 v1903 Diaghub Exploit (< v1903) powershell exploit works

null 12 Nov 9, 2022
Make BAD USB to Reverse Shell with Arduino Digispark (recommended with attiny85)

Make BAD USB to Reverse Shell with Arduino Digispark (recommended with attiny85) Cara Pakai Pastikan Anda telah menginstal Driver Digispark dan mengon

Edo 3 Apr 17, 2022