JUCE: containers

JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
containers
juce_core

## Classes
class | AbstractFifo
| Encapsulates the logic required to implement a lock-free FIFO. More...
class | AbstractFifo::ScopedReadWrite< mode >
| Class for a scoped reader/writer. More...
class | Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >
| Holds a resizable array of primitive or copy-by-value objects. More...
class | ArrayAllocationBase< ElementType, TypeOfCriticalSectionToUse >
| Implements some basic array storage allocation functions. More...
class | ArrayBase< ElementType, TypeOfCriticalSectionToUse >
| A basic object container. More...
class | DynamicObject
| Represents a dynamically implemented object. More...
class | DefaultElementComparator< ElementType >
| A simple ElementComparator class that can be used to sort an array of objects that support the '<' operator. More...
struct | Enumerated< Index, Value >
| Returned when dereferencing an EnumerateIterator. More...
class | EnumerateIterator< Iter, Index >
| An iterator that wraps some other iterator, keeping track of the relative position of that iterator based on calls to arithmetic operators such as operator++(), operator--(), operator+(), and operator-(). More...
class | IteratorPair< Begin, End >
| Wraps a pair of iterators, providing member begin() and end() functions that return those iterators. More...
class | FixedSizeFunction< len, Ret(Args...)>
| A type similar to `std::function` that holds a callable object. More...
struct | DefaultHashFunctions
| A simple class to generate hash functions for some primitive types, intended for use with the HashMap class. More...
class | HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >
| Holds a set of mappings between some key/value pairs. More...
struct | HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::Iterator
| Iterates over the items in a HashMap. More...
class | LinkedListPointer< ObjectType >
| Helps to manipulate singly-linked lists of objects. More...
class | LinkedListPointer< ObjectType >::Appender
| Allows efficient repeated insertions into a list. More...
class | ListenerList< ListenerClass, ArrayType >
| Holds a set of objects and can invoke a member function callback on each object in the set with a single call. More...
struct | ListenerList< ListenerClass, ArrayType >::DummyBailOutChecker
| A dummy bail-out checker that always returns false. More...
class | NamedValueSet
| Holds a set of named var objects. More...
struct | NamedValueSet::NamedValue
| Structure for a named var object. More...
class | Optional< Value >
| A simple optional type. More...
class | OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >
| An array designed for holding objects. More...
class | PropertySet
| A set of named property values, which can be strings, integers, floating point, etc. More...
class | ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >
| Holds a list of objects derived from ReferenceCountedObject, or which implement basic reference-count handling methods. More...
class | ScopedValueSetter< ValueType >
| Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value. More...
class | SingleThreadedAbstractFifo
| Encapsulates the logic for a single-threaded FIFO. More...
class | SortedSet< ElementType, TypeOfCriticalSectionToUse >
| Holds a set of unique primitive objects, such as ints or doubles. More...
class | Span< Value, Extent >
| A non-owning view over contiguous objects stored in an Array or vector or other similar container. More...
class | SparseSet< Type >
| Holds a set of primitive values, storing them as a set of ranges. More...
class | var
| A variant class, that can be used to hold a range of primitive values. More...
struct | var::NativeFunctionArgs
| This structure is passed to a NativeFunction callback, and contains invocation details about the function's arguments and context. More...

## Typedefs
using | Nullopt = std::nullopt_t

## Functions
template<typename Begin , typename End = Begin>
constexpr auto | makeRange (Begin begin, End end)
| Given two iterators "begin" and "end", returns an IteratorPair with a member begin() and end() function.
template<typename Range , typename Index = detail::withAdlSize::AdlSignedSize<Range>>
constexpr auto | enumerate (Range &&range, Index startingValue={})
| Given a range and an optional starting offset, returns an IteratorPair that holds EnumerateIterators wrapping the begin() and end() of the range.
template<size_t len, typename T >
bool | operator!= (const FixedSizeFunction< len, T > &fn, std::nullptr_t)
template<size_t len, typename T >
bool | operator!= (std::nullptr_t, const FixedSizeFunction< len, T > &fn)
template<size_t len, typename T >
bool | operator== (const FixedSizeFunction< len, T > &fn, std::nullptr_t)
template<size_t len, typename T >
bool | operator== (std::nullptr_t, const FixedSizeFunction< len, T > &fn)
template<typename Value >
Optional< std::decay_t< Value > > | makeOptional (Value &&v)
template<typename T , typename End >
| Span (T, End) -> Span< std::remove_pointer_t< decltype(detail::toAddress(std::declval< T >()))> >
template<typename T , size_t N>
| Span (T(&)[N]) -> Span< T, N >
template<typename T , size_t N>
| Span (std::array< T, N > &) -> Span< T, N >
template<typename T , size_t N>
| Span (const std::array< T, N > &) -> Span< const T, N >
template<typename Range >
| Span (Range &&r) -> Span< std::remove_pointer_t< decltype(std::data(r))> >
JUCE_API bool | operator== (const var &, const var &)
| Compares the values of two var objects, using the var::equals() comparison.
JUCE_API bool | operator!= (const var &, const var &)
| Compares the values of two var objects, using the var::equals() comparison.
JUCE_API bool | operator< (const var &, const var &)
| Compares the values of two var objects, using the var::equals() comparison.
JUCE_API bool | operator<= (const var &, const var &)
| Compares the values of two var objects, using the var::equals() comparison.
JUCE_API bool | operator> (const var &, const var &)
| Compares the values of two var objects, using the var::equals() comparison.
JUCE_API bool | operator>= (const var &, const var &)
| Compares the values of two var objects, using the var::equals() comparison.
JUCE_API bool | operator== (const var &, const String &)
JUCE_API bool | operator!= (const var &, const String &)
JUCE_API bool | operator== (const var &, const char *)
JUCE_API bool | operator!= (const var &, const char *)
template<typename ElementComparator , typename TargetValueType >
int | Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::indexOfSorted (ElementComparator &comparator, TargetValueType elementToLookFor) const
| Finds the index of an element in the array, assuming that the array is sorted.
template<class ElementComparator >
void | Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::sort (ElementComparator &comparator, bool retainOrderOfEquivalentItems=false)
| Sorts the elements in the array.
template<class ElementComparator >
int | OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::addSorted (ElementComparator &comparator, ObjectClass *newObject) noexcept
| Inserts a new object into the array assuming that the array is sorted.
template<typename ElementComparator >
int | OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOfSorted (ElementComparator &comparator, const ObjectClass *objectToLookFor) const noexcept
| Finds the index of an object in the array, assuming that the array is sorted.
template<class ElementComparator >
void | OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::sort (ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) noexcept
| Sorts the elements in the array.
template<class ElementComparator >
int | ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOfSorted (ElementComparator &comparator, const ObjectClass *objectToLookFor) const noexcept
| Finds the index of an object in the array, assuming that the array is sorted.
template<class ElementComparator >
void | ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::sort (ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) noexcept
| Sorts the elements in the array.

## Variables
constexpr auto | nullopt = std::nullopt
constexpr auto | dynamicExtent = std::numeric_limits<size_t>::max()

## Detailed Description

## Typedef Documentation

## ◆ Nullopt

using Nullopt = std::nullopt_t

## Function Documentation

## ◆ makeRange()

template<typename Begin , typename End = Begin>

constexpr auto makeRange | ( | Begin | begin,
|  | End | end )
| constexpr

Given two iterators "begin" and "end", returns an IteratorPair with a member begin() and end() function.

This pair can be used in contexts that expect an iterable range, the most significant of which is ranged-for loops. This automatically deduces the Begin and End types, so it is more concise to use than directly calling the IteratorPair constructor.

References begin(), and end().

## ◆ enumerate()

template<typename Range , typename Index = detail::withAdlSize::AdlSignedSize<Range>>

constexpr auto enumerate | ( | Range && | range,
|  | Index | startingValue = {} )
| constexpr

Given a range and an optional starting offset, returns an IteratorPair that holds EnumerateIterators wrapping the begin() and end() of the range.

This is useful in situations where you need to iterate some range, but also query the position of each item in the range.

A simple usage might look like this:

std::list<int> elements { 10, 20, 30, 40, 50 };
for (const auto pair : enumerate (elements))
std::cout << pair.index << ' ' << pair.value << ' ';
// output: 0 10 1 20 2 30 3 40 4 50
enumerate
constexpr auto enumerate(Range &&range, Index startingValue={})
Given a range and an optional starting offset, returns an IteratorPair that holds EnumerateIterators ...
Definition juce_Enumerate.h:420

You can also use structured bindings to concisely destructure each Enumerated instance:

for (const auto [index, value] : enumerate (elements))
std::cout << index << ' ' << value << ' ';

Note that the Enumerated instance is returned by value. This is because each Enumerated instance is created on-demand when the iterator is dereferenced. As a result, the following will result in a dangling reference, and will probably trigger a compiler warning:

// BAD IDEA: creating a reference to a temporary Enumerated instance
for (auto& [index, value] : enumerate (elements))
...

The 'value' member of Enumerated automatically assumes the same type as dereferencing the wrapped iterator, which is normally a reference to an element of a container. In the following snippet, the type of '[index, value]' is 'const Enumerated<ptrdiff_t, int&>', the type of 'index' is 'ptrdiff_t', and the type of 'value' is 'int&'.

std::vector<int> elements { 10, 20, 30, 40, 50 };
for (const auto [index, value] : enumerate (elements))
...

By default, the constness of pair.value will match the constness of the range passed to enumerate. If you pass a mutable lvalue reference to enumerate, then each value will also be mutable. If you pass a constant lvalue reference to enumerate, then each value will be const. If you know that you don't need the iterated elements to be mutable, it's good practice to wrap the range with std::as_const before passing it to enumerate:

for (const auto [index, value] : enumerate (std::as_const (elements)))
{
// value is immutable here
}

## ◆ operator!=() [1/5]

template<size_t len, typename T >

bool operator!= | ( | const FixedSizeFunction< len, T > & | fn,
|  | std::nullptr_t | )

## ◆ operator!=() [2/5]

template<size_t len, typename T >

bool operator!= | ( | std::nullptr_t | ,
|  | const FixedSizeFunction< len, T > & | fn )

## ◆ operator==() [1/5]

template<size_t len, typename T >

bool operator== | ( | const FixedSizeFunction< len, T > & | fn,
|  | std::nullptr_t | )

## ◆ operator==() [2/5]

template<size_t len, typename T >

bool operator== | ( | std::nullptr_t | ,
|  | const FixedSizeFunction< len, T > & | fn )

## ◆ makeOptional()

template<typename Value >

Optional< std::decay_t< Value > > makeOptional | ( | Value && | v | ) |

## ◆ Span() [1/5]

template<typename T , typename End >

Span | ( | T | ,
|  | End | ) -> Span< std::remove_pointer_t< decltype(detail::toAddress(std::declval< T >()))> >

## ◆ Span() [2/5]

template<typename T , size_t N>

Span | ( | T(&) | [N] | ) | -> Span< T, N >

## ◆ Span() [3/5]

template<typename T , size_t N>

Span | ( | std::array< T, N > & |  | ) | -> Span< T, N >

## ◆ Span() [4/5]

template<typename T , size_t N>

Span | ( | const std::array< T, N > & |  | ) | -> Span< const T, N >

## ◆ Span() [5/5]

template<typename Range >

Span | ( | Range && | r | ) | -> Span< std::remove_pointer_t< decltype(std::data(r))> >

## ◆ operator==() [3/5]

JUCE_API bool operator== | ( | const var & | ,
|  | const var & | )

Compares the values of two var objects, using the var::equals() comparison.

## ◆ operator!=() [3/5]

JUCE_API bool operator!= | ( | const var & | ,
|  | const var & | )

Compares the values of two var objects, using the var::equals() comparison.

## ◆ operator<()

JUCE_API bool operator< | ( | const var & | ,
|  | const var & | )

Compares the values of two var objects, using the var::equals() comparison.

Referenced by LookAndFeel::playAlertSound().

## ◆ operator<=()

JUCE_API bool operator<= | ( | const var & | ,
|  | const var & | )

Compares the values of two var objects, using the var::equals() comparison.

## ◆ operator>()

JUCE_API bool operator> | ( | const var & | ,
|  | const var & | )

Compares the values of two var objects, using the var::equals() comparison.

## ◆ operator>=()

JUCE_API bool operator>= | ( | const var & | ,
|  | const var & | )

Compares the values of two var objects, using the var::equals() comparison.

## ◆ operator==() [4/5]

JUCE_API bool operator== | ( | const var & | ,
|  | const String & | )

## ◆ operator!=() [4/5]

JUCE_API bool operator!= | ( | const var & | ,
|  | const String & | )

## ◆ operator==() [5/5]

JUCE_API bool operator== | ( | const var & | ,
|  | const char * | )

## ◆ operator!=() [5/5]

JUCE_API bool operator!= | ( | const var & | ,
|  | const char * | )

## ◆ indexOfSorted() [1/3]

template<typename ElementType , typename TypeOfCriticalSectionToUse , int minimumAllocatedSize>
template<typename ElementComparator , typename TargetValueType >

int Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::indexOfSorted | ( | ElementComparator & | comparator,
|  | TargetValueType | elementToLookFor ) const

Finds the index of an element in the array, assuming that the array is sorted.

This will use a comparator to do a binary-chop to find the index of the given element, if it exists. If the array isn't sorted, the behaviour of this method will be unpredictable.

Parameters

  comparator | the comparator to use to compare the elements - see the sort() method for details about the form this object should take
  elementToLookFor | the element to search for

Returns
  the index of the element, or -1 if it's not found

See also
  addSorted, sort

References ArrayBase< ElementType, TypeOfCriticalSectionToUse >::size().

## ◆ sort() [1/3]

template<typename ElementType , typename TypeOfCriticalSectionToUse , int minimumAllocatedSize>
template<class ElementComparator >

void Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::sort | ( | ElementComparator & | comparator,
|  | bool | retainOrderOfEquivalentItems = false )

Sorts the elements in the array.

This will use a comparator object to sort the elements into order. The object passed must have a method of the form:

int compareElements (ElementType first, ElementType second);

..and this method must return:

- a value of < 0 if the first comes before the second
- a value of 0 if the two objects are equivalent
- a value of > 0 if the second comes before the first

To improve performance, the compareElements() method can be declared as static or const.

Parameters

  comparator | the comparator to use for comparing elements.
  retainOrderOfEquivalentItems | if this is true, then items which the comparator says are equivalent will be kept in the order in which they currently appear in the array. This is slower to perform, but may be important in some cases. If it's false, a faster algorithm is used, but equivalent elements may be rearranged.

See also
  addSorted, indexOfSorted, sortArray

References ArrayBase< ElementType, TypeOfCriticalSectionToUse >::begin().

## ◆ addSorted()

template<class ObjectClass , class TypeOfCriticalSectionToUse >
template<class ElementComparator >

int OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::addSorted | ( | ElementComparator & | comparator,
|  | ObjectClass * | newObject )
| noexcept

Inserts a new object into the array assuming that the array is sorted.

This will use a comparator to find the position at which the new object should go. If the array isn't sorted, the behaviour of this method will be unpredictable.

Parameters

  comparator | the comparator to use to compare the elements - see the sort method for details about this object's structure
  newObject | the new object to insert to the array

Returns
  the index at which the new object was added

See also
  add, sort, indexOfSorted

References ArrayBase< ElementType, TypeOfCriticalSectionToUse >::begin(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::getLock(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::insert(), and ArrayBase< ElementType, TypeOfCriticalSectionToUse >::size().

## ◆ indexOfSorted() [2/3]

template<class ObjectClass , class TypeOfCriticalSectionToUse >
template<typename ElementComparator >

int OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOfSorted | ( | ElementComparator & | comparator,
|  | const ObjectClass * | objectToLookFor ) const
| noexcept

Finds the index of an object in the array, assuming that the array is sorted.

This will use a comparator to do a binary-chop to find the index of the given element, if it exists. If the array isn't sorted, the behaviour of this method will be unpredictable.

Parameters

  comparator | the comparator to use to compare the elements - see the sort() method for details about the form this object should take
  objectToLookFor | the object to search for

Returns
  the index of the element, or -1 if it's not found

See also
  addSorted, sort

References OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::getLock(), and ArrayBase< ElementType, TypeOfCriticalSectionToUse >::size().

## ◆ sort() [2/3]

template<class ObjectClass , class TypeOfCriticalSectionToUse >
template<typename ElementComparator >

void OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::sort | ( | ElementComparator & | comparator,
|  | bool | retainOrderOfEquivalentItems = false )
| noexcept

Sorts the elements in the array.

This will use a comparator object to sort the elements into order. The object passed must have a method of the form:

int compareElements (ElementType* first, ElementType* second);

..and this method must return:

- a value of < 0 if the first comes before the second
- a value of 0 if the two objects are equivalent
- a value of > 0 if the second comes before the first

To improve performance, the compareElements() method can be declared as static or const.

Parameters

  comparator | the comparator to use for comparing elements.
  retainOrderOfEquivalentItems | if this is true, then items which the comparator says are equivalent will be kept in the order in which they currently appear in the array. This is slower to perform, but may be important in some cases. If it's false, a faster algorithm is used, but equivalent elements may be rearranged.

See also
  sortArray, indexOfSorted

References ArrayBase< ElementType, TypeOfCriticalSectionToUse >::begin(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::getLock(), and OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::size().

Referenced by ValueTree::sort().

## ◆ indexOfSorted() [3/3]

template<class ObjectClass , class TypeOfCriticalSectionToUse >
template<class ElementComparator >

int ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOfSorted | ( | ElementComparator & | comparator,
|  | const ObjectClass * | objectToLookFor ) const
| noexcept

Finds the index of an object in the array, assuming that the array is sorted.

This will use a comparator to do a binary-chop to find the index of the given element, if it exists. If the array isn't sorted, the behaviour of this method will be unpredictable.

Parameters

  comparator | the comparator to use to compare the elements - see the sort() method for details about the form this object should take
  objectToLookFor | the object to search for

Returns
  the index of the element, or -1 if it's not found

See also
  addSorted, sort

References ArrayBase< ElementType, TypeOfCriticalSectionToUse >::size().

## ◆ sort() [3/3]

template<class ObjectClass , class TypeOfCriticalSectionToUse >
template<class ElementComparator >

void ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::sort | ( | ElementComparator & | comparator,
|  | bool | retainOrderOfEquivalentItems = false )
| noexcept

Sorts the elements in the array.

This will use a comparator object to sort the elements into order. The object passed must have a method of the form:

int compareElements (ElementType first, ElementType second);

..and this method must return:

- a value of < 0 if the first comes before the second
- a value of 0 if the two objects are equivalent
- a value of > 0 if the second comes before the first

To improve performance, the compareElements() method can be declared as static or const.

Parameters

  comparator | the comparator to use for comparing elements.
  retainOrderOfEquivalentItems | if this is true, then items which the comparator says are equivalent will be kept in the order in which they currently appear in the array. This is slower to perform, but may be important in some cases. If it's false, a faster algorithm is used, but equivalent elements may be rearranged.

See also
  sortArray

References ArrayBase< ElementType, TypeOfCriticalSectionToUse >::begin(), and ArrayBase< ElementType, TypeOfCriticalSectionToUse >::size().

## Variable Documentation

## ◆ nullopt

constexpr auto nullopt = std::nullopt
| constexpr

## ◆ dynamicExtent

constexpr auto dynamicExtent = std::numeric_limits<size_t>::max()
| constexpr