Basic Concepts

Overview

Here are the basic C++ concepts used by the Q DSP library.

Include

#include <q/support/basic_concepts.hpp>

Arithmetic

The Arithmetic concept is a model of the std::integral OR the std::floating_point concept.

Declaration

namespace cycfi::q::concepts
{
   template <typename T>
   concept Arithmetic = std::integral<T> || std::floating_point<T>;
}

IndexableContainer

IndexableContainer is a concept that represents an indexable data type. Essentially, it must be indexable using the indexing subscript operator [] with a subscript convertable from std::size_t, and has a size() member function that returns the size of the Container or View being indexed.

Declaration

namespace cycfi::q::concepts
{
   template <typename T>
   concept IndexableContainer = requires(T& x, std::size_t i)
   {
      { x[i] } -> std::convertible_to<typename T::value_type>;
      { x.size() } -> std::convertible_to<std::size_t>;
   };
}

IndexableContainer types allow standard for-loop iteration:

for (auto i = 0; i != c.size() ++i)
{
   c[i];
}

Where c is an instance of IndexableContainer.

RandomAccessIteratable

RandomAccessIteratable is a concept that represents a random-access iteratable data type, which has begin() and end() member functions, and the return type of both functions is an iterator that conforms to the std::random_access_iterator concept.

Declaration

namespace cycfi::q::concepts
{
   template <typename T>
   concept RandomAccessIteratable =
      std::random_access_iterator<typename T::iterator> &&
      requires(T& c)
   {
      { c.begin() } -> std::same_as<typename T::iterator>;
      { c.end() } -> std::same_as<typename T::iterator>;
   };
}

RandomAccessIteratable allows C++ range-based for loop syntax:

for (auto e : c)
{
   /**...**/
}

Where c is an instance of RandomAccessIteratable and e is an element of c.