A C++20 concepts library, providing container concepts etc.

Overview

More concepts

#include <more_concepts/more_concepts.hpp>

This library aims to provide general purpose concepts that are not available in the C++20 concepts library, most notably container concepts. It also provides utilities for writing your own concepts (a mock_iterator that can mock any iterator category - see bellow).

Notes

At the moment, only GCC 10.2 is confirmed to be able to compile all of this library.

Installing with Conan

If you use Conan to manage dependencies, you can get this library from my artifactory.

  1. Add my artifactory repository to your local Conan install: conan remote add miso1289 https://miso1289.jfrog.io/artifactory/api/conan/miso1289
  2. Add the reference to your conanfile.txt (or conanfile.py), e.g. more_concepts/[email protected]/stable
  3. Install the dependency before building: conan install -b missing $CONAN_DIR, where CONAN_DIR is your top-level directory (containing your conanfile).

Container concepts

The container concepts are intended to serve as an abstraction for the STL container interfaces, allowing writing constrained generic code that can use any container of some category, both standard and third-party (as long as it provides an STL compliant interface).

While a lot of generic algorithms can do with range and iterator concepts, this is sometimes not enough - for example, how does one write a constrained container adaptor? Let's say you want to implement a priority queue that can use any index-able sequence type with back-insertion to store the heap. Using this library, you could express this as:

template <typename T, 
          more_concepts::random_access_container_of Seq = std::vector>
requires more_concepts::back_growable_container
class priority_queue;

General container concepts

#include <more_concepts/base_containers.hpp>
  • container - Satisfied by all well-behaved (not vector) standard containers.
  • mutable_container - A container that allows mutable iteration. Satisfied by all standard containers except set.
  • sized_container - A container that knows its size. Satisfied by all standard containers except forward_list.
  • clearable_container - A container that can be cleared . Satisfied by all standard containers except array.
  • reversible_container - A container that allows reverse iteration. Satisfied by all standard containers except forward_list.

For each of the above, an _of version is provided (e.g. reversible_container_of), that also requires the value_type to be the same as specified.

Sequence container concepts

#include <more_concepts/sequence_containers.hpp>
  • sequence_container - A mutable container that represents linear ordering of elements (corresponds to the standard SequenceContainer named requirement). Provides efficient access to the beginning of the sequence. Satisfied by all standard sequence containers, namely vector, array, basic_string, deque, list, and forward_list.
  • double_ended_container - A sized and reversible sequence container that provides efficient access to the end of the sequence. Satisfied by all standard sequence containers except forward_list.
  • random_access_container - A double-ended sequence container that provides indexed access to elements. Satisfied by vector, array, basic_string, and deque.
  • contiguous_container - A random-access sequence container, stored contiguously in memory. Satisfied by vector, array, and basic_string.
  • resizable_sequence_container - A clearable double-ended container that allows resizing, range construction and assignment, and insertion / erasure in the middle). Satisfied by vector, basic_string, deque, and list.
  • inplace_constructing_sequence_container - Extends the resizable_sequence_container interface with in-place construction. Satisfied by all standard models of resizable_sequence_container except basic_string.
  • front_growable_container - A sequence container that allows efficient inserting / erasure at the front. Satisfied by deque, list, and forward_list.
  • inplace_front_constructing_container - Extends the front_growable_container interface with in-place construction. Satisfied by all standard models of front_growable_container.
  • back_growable_container - A double-ended container that allows efficient inserting / erasure at the back. Satisfied by vector, basic_string, deque, and list.
  • inplace_back_constructing_container - Extends the back_growable_container interface with in-place construction. Satisfied by all standard models of back_growable_container except basic_string.

For each sequence container concept, an _of version is also provided.

Associative container concepts

#include <more_concepts/associative_containers.hpp>
  • associative_container - A container that provides fast lookup of objects based on keys. Represents a union of the standard named requirements AssociativeContainer and UnorderedAssociativeContainer. Satisfied by all standard associative containers.
  • unique_associative_container - An associative container with unique keys. Satisfied by set, map, unordered_set and unordered_map.
  • multiple_associative_container - An associative container with non-unique keys. Satisfied by multiset, multimap, unordered_multiset and unordered_multimap.
  • map_container - An associative container representing a key-value mapping. Satisfied by map, multimap, unordered_map and unordered_multimap.
  • unique_map_container - A map container with unique keys. Satisfied by map and unordered_map.
  • multiple_map_container - A map container with non-unique keys. Satisfied by multimap and unordered_multimap.

For each associative container / map concept, ordered_ and unordered_ versions are available (e.g. ordered_unique_map_container).

For each generic (non-map) associative container concept, an _of version is available.

For each map container concept, an _of version is available.

General concepts

#include <more_concepts/base_concepts.hpp>

Concepts that are simple wrappers over standard type traits:

  • decayed - Types that are non-reference, non-c-array, non-function or function reference, non-const and non-volatile. Assigning an object of this type to an auto variable preserves the type. Used to constrain the value_type of containers.
  • aggregate - Types that support aggregate initialization.
  • trivial - Types that can be memcpy-ied, and don't need any (non-trivial) initialization or destruction.
  • enum_type - Scoped and unscoped enumeration types.
  • error_code_enum - Error enum that can be used to construct a std::error_code.
  • error_condition_enum - Error enum that can be used to construct a std::error_condition.

Function concepts:

  • invocable_as - Function types that can be called with std::invoke using one or more function signatures. The return type of each signature is only checked for convertibility.
  • callable_as - Function types that can be called with the function-call operator using one or more function signatures. The return type of each signature must be matched exactly.
  • hash_function - corresponds to the Hash standard named requirement. Used to define the unordered_associative_container concept.

Utilities

Mock iterator

#include <more_concepts/mock_iterator.hpp>

The mock_iterator class template can be used to write concepts that require some operation to accept any iterator of some category.

Template parameters:

  • T - iterator value type.
  • IteratorCategory - can be one of the standard iterator category tags (e.g. std::input_iterator_tag). The mock iterator provides the minimal needed interface to satisfy the requested category. E.g. for the input and output iterator categories, a proxy reference type is used instead of a raw reference.
  • RWCategory - can be one of mutable_iterator_tag, const_iterator_tag. Indicates whether the mock iterator should support write access.
Comments
  • Add cmake install

    Add cmake install

    I have added cmake install commands to do a clean install of the library.

    I have not used Conan before, but I think it can call cmake to do the installation.

    opened by kenanmarasli 4
  • (Fixed) Add cmake install

    (Fixed) Add cmake install

    Apparently relative paths in generator expressions are not valid for the build tree.

    I have activated the github actions and tested the last commit, it passes. It will be good to enable it for PRs from forks too.

    opened by kenanmarasli 2
  • Add option to include tests

    Add option to include tests

    BUILD_TESTING option is used whether to include and enable testing or not.

    It's an already existing option that can be set beforehand and to OFF by default, so users of the library do not need to include tests.

    See: enable_testing

    opened by kenanmarasli 2
  • 'const' issues

    'const' issues

    I'm calling a constrained function from within a const member function, so the container is being marked const, and subsequently fails the concept check because a const vector is apparently not a container (because it's not moveable).

    Ignore - this turns out to be misleading diagnostics, the actual problem was I was passing the const container to a non-const ref, however it was showing up as a concept fail.

    opened by mark-99 0
  • Compile error on clang 13 & msvc 19

    Compile error on clang 13 & msvc 19

    base_concepts line 51 fails to compile with "unexpanded parameter pack":

        requires(Signatures& ... signatures)
        {
            ([] <typename Ret, typename... Args>(auto(&)(Args...) -> Ret)
            requires std::is_invocable_r_v<Ret, Fn, Args>
            {}(signatures), ...);
        };
    

    It should be this (like the same thing at line 64):

     requires std::is_invocable_r_v<Ret, Fn, Args...>
    
    opened by mark-99 0
Releases(v0.1.0)
Owner
Michal Jankovič
Michal Jankovič
Isocline is a pure C library that can be used as an alternative to the GNU readline library

Isocline: a portable readline alternative. Isocline is a pure C library that can be used as an alternative to the GNU readline library (latest release

Daan 136 Dec 30, 2022
A linux library to get the file path of the currently running shared library. Emulates use of Win32 GetModuleHandleEx/GetModuleFilename.

whereami A linux library to get the file path of the currently running shared library. Emulates use of Win32 GetModuleHandleEx/GetModuleFilename. usag

Blackle Morisanchetto 3 Sep 24, 2022
Command-line arguments parsing library.

argparse argparse - A command line arguments parsing library in C (compatible with C++). Description This module is inspired by parse-options.c (git)

Yecheng Fu 533 Dec 26, 2022
A cross platform C99 library to get cpu features at runtime.

cpu_features A cross-platform C library to retrieve CPU features (such as available instructions) at runtime. Table of Contents Design Rationale Code

Google 2.2k Dec 22, 2022
Library that solves the exact cover problem using Dancing Links, also known as DLX.

The DLX Library The DLX library The DLX library solves instances of the exact cover problem, using Dancing Links (Knuth’s Algorithm X). Also included

Ben Lynn 44 Dec 18, 2022
Standards compliant, fast, secure markdown processing library in C

Hoedown Hoedown is a revived fork of Sundown, the Markdown parser based on the original code of the Upskirt library by Natacha Porté. Features Fully s

Hoedown 923 Dec 27, 2022
CommonMark parsing and rendering library and program in C

cmark cmark is the C reference implementation of CommonMark, a rationalized version of Markdown syntax with a spec. (For the JavaScript reference impl

CommonMark 1.4k Jan 4, 2023
A cross-platform protocol library to communicate with iOS devices

libimobiledevice A library to communicate with services on iOS devices using native protocols. Features libimobiledevice is a cross-platform software

libimobiledevice 5.4k Dec 30, 2022
Platform independent Near Field Communication (NFC) library

*- * Free/Libre Near Field Communication (NFC) library * * Libnfc historical contributors: * Copyright (C) 2009 Roel Verdult * Copyright (C) 2009

null 1.4k Jan 5, 2023
A C library for parsing/normalizing street addresses around the world. Powered by statistical NLP and open geo data.

libpostal: international street address NLP libpostal is a C library for parsing/normalizing street addresses around the world using statistical NLP a

openvenues 3.6k Dec 27, 2022
Your friendly e-mail address validation library.

libvldmail Your friendly e-mail address validation library. Why? Did you know that parentheses, spaces and - according to the RFC 6531 document - emoj

Cthulhux 47 Sep 28, 2022
A protocol buffers library for C

PBC PBC is a google protocol buffers library for C without code generation. Quick Example package tutorial; message Person { required string name =

云风 1.6k Dec 28, 2022
An easy-to-use C library for displaying text progress bars.

What is this thing? progressbar is a C-class (it's a convention, dammit) for displaying attractive progress bars on the command line. It's heavily inf

Trevor Fountain 440 Dec 27, 2022
Library for writing text-based user interfaces

IMPORTANT This library is no longer maintained. It's pretty small if you have a big project that relies on it, just maintain it yourself. Or look for

null 1.9k Dec 22, 2022
Locate the current executable and the current module/library on the file system

Where Am I? A drop-in two files library to locate the current executable and the current module on the file system. Supported platforms: Windows Linux

Gregory Pakosz 382 Dec 27, 2022
A small and portable INI file library with read/write support

minIni minIni is a portable and configurable library for reading and writing ".INI" files. At just below 900 lines of commented source code, minIni tr

Thiadmer Riemersma 293 Dec 29, 2022
Small configuration file parser library for C.

libConfuse Introduction Documentation Examples Build & Install Origin & References Introduction libConfuse is a configuration file parser library writ

null 419 Dec 14, 2022
Libelf is a simple library to read ELF files

libelf Libelf is a simple library which provides functions to read ELF files. Headers #include <stdint.h> #include <elf.h> Structures typedef struct

David du Colombier 44 Aug 7, 2022
Universal configuration library parser

LIBUCL Table of Contents generated with DocToc Introduction Basic structure Improvements to the json notation General syntax sugar Automatic arrays cr

Vsevolod Stakhov 1.5k Dec 28, 2022