The Library

- Algorithms
- API Wrappers
- Bayesian Nets
- Compression
- Containers
- Graph Tools
- Image Processing
- Linear Algebra
- Machine Learning
- Metaprogramming
- Miscellaneous
- Networking
- Optimization
- Parsing

Help/Info

- Examples: C++
  - 3D_Point_Cloud
  - Assignment_Learning
  - Base64_Encoder
  - Bayesian_Network
  - Bayesian_Network_From_Disk
  - Bayesian_Network_GUI
  - Bridge
  - BSP
  - C-Support_Vector_Machine
  - Cmd_Line_Parser
  - Compress_Stream
  - Config_File_Reader
  - Custom_Trainers
  - Directory_Navigation
  - Empirical_Kernel_Map
  - Face_Detection
  - Face_Landmark_Detection
  - FHOG_Feature_Extraction
  - FHOG_Object_Detection
  - Graph_Labeling
  - GUI
  - Hough_Transform
  - HTTP_Server
  - Image
  - IO Socket Streams
  - IO Streams Server
  - Kernel_Centroid
  - Kernel_K-Means_Clustering
  - Kernel_Ridge_Regression
  - Kernel_RLS_Filtering
  - Kernel_RLS_Regression
  - KRR_Classification
  - Learning_to_Track
  - Linear_Assignment_Problems
  - Linear_Manifold_Regularizer
  - Logger
  - Logger_Advanced
  - Logger_Custom_Output
  - Matrix
  - Matrix_Expressions
  - Member_Function_Pointer
  - Model_Selection
  - Multiclass_Classification
  - Multithreaded_Object
  - Neural_Network
  - Non-Linear Least Squares
  - Nu-Support_Vector_Machine
  - Numerical_Integration
  - Object_Detector
  - Object_Detector_Advanced
  - One_Class_Classifiers
  - Online_SVM
  - Optimization
  - Parallel_For_Loops
  - Pipe
  - Pipe_2
  - Quantum_Computing
  - Queue
  - Rank_Features
  - Relevance_Vector_Classification
  - Relevance_Vector_Regression
  - Running_Stats
  - Sequence_Labeling
  - Sequence_Segmentation
  - Sockets
  - Sockstreambuf
  - Sparse_Vectors
  - SQLite
  - Std_C++_Allocator
  - Structural_Support_Vector_Machines
  - Support_Vector_Regression
  - SURF
  - SVM-Rank
  - Threaded_Object
  - Threads
  - Thread_Function
  - Thread_Pool
  - Timer
  - Train_Object_Detector
  - Train_Shape_Predictor
  - Using_Custom_Kernels
  - Video_Object_Tracking
  - Webcam_Face_Pose_Estimation
  - XML_Parser
- Examples: Python
  - Face_Detector
  - Face_Landmark_Detection
  - find_candidate_object_locations
  - Linear_Assignment_Problems
  - Sequence_Segmenter
  - Structural_Support_Vector_Machines
  - SVM-Rank
  - Train_Object_Detector
  - Train_Shape_Predictor
- FAQ
- Home
- How to compile
- How to contribute
- Index
- Introduction
- License
- Python API
- Suggested Books

Current Release

- Change Log
- Release Notes
- Version: 18.15

Last Modified: Feb 28, 2013

# Containers

Many of these containers were inspired by the work of the Reusable Software Research Group at Ohio State. As such, many of the objects do not support copying in any form, only swapping is allowed. That is, when objects are added or removed from most of these containers they are swapped in and out, not copied.

This allows you to do things like have containers of containers of containers without encountering the overhead of the massive copying that would likely result if you did the same thing with the STL. It also means you can store objects that are not copyable inside these containers, which is not something you can do with the STL prior to C++11.

Note that it is assumed by these containers that swap() and operator< do not throw. They may not function correctly if this assumption is broken. Also note that the built in types (int, long, char, etc.) and std::string will not cause operator< or swap() to throw.

Note also that most of the containers inherit from the enumerable interface. Thus, all the member functions inherited from enumerable are defined in the enumerable class and their documentation is not repeated in each container's documentation. This includes the size() member function in each container.

Objects

- any
- any_decision_function
- any_function
- any_trainer
- array
- array2d
- binary_search_tree
- circular_buffer
- directed_graph
- graph
- hash_map
- hash_set
- hash_table
- map
- queue
- reference_counter
- reference_wrapper
- sequence
- set
- sliding_buffer
- stack
- static_map
- static_set
- std_vector_c
- tuple
- type_safe_union
- unordered_pair

Smart Pointers

- scoped_ptr
- shared_ptr
- shared_ptr_thread_safe
- weak_ptr

Interfaces

- enumerable
- map_pair
- remover
  - asc_pair_remover
  - asc_remover
  - pair_remover
  - remover

[top]

# any

This object is basically a type-safe version of a void*. In particular, it is a container which can contain only one object but the object may be of any type.

It is somewhat like the type_safe_union except you don't have to declare the set of possible content types beforehand. So in some sense this is like a less type-strict version of the type_safe_union.

`#include <dlib/any.h>`
Detailed Documentation
[top]

# any_decision_function

This object is a version of dlib::any that is restricted to containing elements which are some kind of function object with an operator() with the following signature: `result_type operator()(const sample_type&) const`

It is intended to be used to contain dlib::decision_function objects and other types which represent learned decision functions. It allows you to write code which contains and processes these decision functions without needing to know the specific types of decision functions used.

`#include <dlib/any.h>`
Detailed Documentation
[top]

# any_function

This object is a version of dlib::any that is restricted to containing elements which are some kind of function or function object.
`#include <dlib/any.h>`
Detailed Documentation
[top]

# any_trainer

This object is a version of dlib::any that is restricted to containing elements which are some kind of object with a .train() method compatible with the following signature:

     decision_function train(
          const std::vector<sample_type>& samples,
          const std::vector<scalar_type>& labels
       ) const

Where `decision_function` is a type capable of being stored in an any_decision_function object.

any_trainer is intended to be used to contain objects such as the svm_nu_trainer and other similar types which represent supervised machine learning algorithms. It allows you to write code which contains and processes these trainer objects without needing to know the specific types of trainer objects used.

`#include <dlib/any.h>`
Detailed Documentation
[top]

# array

This object represents a 1-Dimensional array of objects.
`#include <dlib/array.h>`
Detailed Documentation
[top]

# array2d

This object represents a 2-Dimensional array of objects.
`#include <dlib/array2d.h>`
Detailed Documentation
C++ Example Programs: image_ex.cpp
[top]

# binary_search_tree

This object represents a data dictionary that is built on top of some kind of binary search tree.
`#include <dlib/binary_search_tree.h>`
Detailed Documentation
Implementations:

> binary_search_tree_kernel_1:
> This implementation is done using an AVL binary search tree. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for binary_search_tree_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

> binary_search_tree_kernel_2:
> This implementation is done using a red-black binary search tree. It uses the memory_manager for all memory allocations.

> kernel_2a | is a typedef for binary_search_tree_kernel_2
> kernel_2a_c | is a typedef for kernel_2a that checks its preconditions.

[top]

# circular_buffer

This object represents a simple sliding buffer which can contain and arbitrary number of elements.
`#include <dlib/sliding_buffer.h>`
Detailed Documentation
[top]

# directed_graph

This object represents a directed graph which is a set of nodes with directed edges connecting various nodes.
`#include <dlib/directed_graph.h>`
Detailed Documentation
Implementations:

> directed_graph_kernel_1:
> This is implemented using std::vector to contain all the nodes and edges.

> kernel_1a | is a typedef for directed_graph_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

[top]

# enumerable

This object is an abstract class which represents an interface for iterating over all the elements of a container.
`#include <dlib/interfaces/enumerable.h>`
Detailed Documentation
[top]

# graph

This object represents a graph which is a set of nodes with undirected edges connecting various nodes.
`#include <dlib/graph.h>`
Detailed Documentation
Implementations:

> graph_kernel_1:
> This is implemented using std::vector to contain all the nodes and edges.

> kernel_1a | is a typedef for graph_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

[top]

# hash_map

This object represents a hashed mapping of items of type domain onto items of type range.
`#include <dlib/hash_map.h>`
Detailed Documentation
Implementations:

> hash_map_kernel_1:
> This implementation is done using a hash_table object. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for hash_map_kernel_1 that uses hash_table_kernel_1a
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.
> kernel_1b | is a typedef for hash_map_kernel_1 that uses hash_table_kernel_2a
> kernel_1b_c | is a typedef for kernel_1b that checks its preconditions.
> kernel_1c | is a typedef for hash_map_kernel_1 that uses hash_table_kernel_2b
> kernel_1c_c | is a typedef for kernel_1c that checks its preconditions.

[top]

# hash_set

This object represents a hashed unordered and unaddressed collection of unique items.
`#include <dlib/hash_set.h>`
Detailed Documentation
Implementations:

> hash_set_kernel_1:
> This implementation is done using a hash_table object. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for hash_set_kernel_1 that uses hash_table_kernel_1a
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.
> kernel_1b | is a typedef for hash_set_kernel_1 that uses hash_table_kernel_2a
> kernel_1b_c | is a typedef for kernel_1b that checks its preconditions.
> kernel_1c | is a typedef for hash_set_kernel_1 that uses hash_table_kernel_2b
> kernel_1c_c | is a typedef for kernel_1c that checks its preconditions.

[top]

# hash_table

This object represents a data dictionary that is built on top of some kind of hash table.
`#include <dlib/hash_table.h>`
Detailed Documentation
Implementations:

> hash_table_kernel_1:
> This implementation is done using singly linked lists as hashing buckets. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for hash_table_kernel_1.
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

> hash_table_kernel_2:
> This implementation is done using binary_search_tree objects as hashing buckets. It uses the memory_manager for all memory allocations.

> kernel_2a | is a typedef for hash_table_kernel_2 that uses binary_search_tree_kernel_1
> kernel_2a_c | is a typedef for kernel_2a that checks its preconditions.
> kernel_2b | is a typedef for hash_table_kernel_2 that uses binary_search_tree_kernel_2
> kernel_2b_c | is a typedef for kernel_2b that checks its preconditions.

[top]

# map

This object represents a mapping of items of type domain onto items of type range.
`#include <dlib/map.h>`
Detailed Documentation
Implementations:

> map_kernel_1:
> This is implemented using the binary_search_tree component. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for map_kernel_1 that uses binary_search_tree_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.
> kernel_1b | is a typedef for map_kernel_1 that uses binary_search_tree_kernel_2
> kernel_1b_c | is a typedef for kernel_1b that checks its preconditions.

[top]

# map_pair

This object is an abstract class which represents an interface for accessing a pair from a container such as the map, hash_table, etc.
`#include <dlib/interfaces/map_pair.h>`
Detailed Documentation
[top]

# queue

This object represents a first in first out queue.
`#include <dlib/queue.h>`
Detailed Documentation
C++ Example Programs: queue_ex.cpp
Implementations:

> queue_kernel_1:
> This is implemented in the obvious way using a singly linked list. It does not use the memory_manager at all.

> kernel_1a | is a typedef for queue_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

> queue_kernel_2:
> This is implemented using a singly linked list and each node in the list contains block_size (a template parameter) elements. It uses the memory_manager for all memory allocations.

> kernel_2a | is a typedef for queue_kernel_2 with a block_size of 20
> kernel_2a_c | is a typedef for kernel_2a that checks its preconditions.
> kernel_2b | is a typedef for queue_kernel_2 with a block_size of 100
> kernel_2b_c | is a typedef for kernel_2b that checks its preconditions.

# Extensions to queue

queue_sort
This extension gives a queue the ability to sort its contents.
Detailed Documentation
Implementations:

> queue_sort_1:
> This is a version of the QuickSort algorithm.

> sort_1a | is a typedef for queue_kernel_1a extended by queue_sort_1
> sort_1a_c | is a typedef for sort_1a that checks its preconditions.
> sort_1b | is a typedef for queue_kernel_2a extended by queue_sort_1
> sort_1b_c | is a typedef for sort_1b that checks its preconditions.
> sort_1c | is a typedef for queue_kernel_2b extended by queue_sort_1
> sort_1c_c | is a typedef for sort_1c that checks its preconditions.

[top]

# reference_counter

This object represents a container for an object and provides reference counting capabilities for the object it contains.
`#include <dlib/reference_counter.h>`
Detailed Documentation
Implementations:

> reference_counter_kernel_1:
> This implementation is done using pointers in the obvious way.

> kernel_1a | is a typedef for reference_counter_kernel_1

[top]

# reference_wrapper

This is a simple object that just holds a reference to another object. It is useful because it can serve as a kind of "copyable reference".
`#include <dlib/ref.h>`
Detailed Documentation
C++ Example Programs: thread_function_ex.cpp
[top]

# remover

This is a set of interfaces which gives the ability to remove all the items in a container without actually knowing what kind of container contains them.
`#include <dlib/interfaces/remover.h>`
Detailed Documentation
[top]

# scoped_ptr

This is a implementation of the scoped_ptr class found in the Boost C++ library. It is a simple smart pointer class which guarantees that the pointer contained within it will always be deleted. The class does not permit copying and so does not do any kind of reference counting. Thus it is very simple and quite fast.
`#include <dlib/smart_pointers.h>`
Detailed Documentation
[top]

# sequence

This object represents an ordered sequence of items, each item is associated with an integer value. The items are numbered from 0 to the number of items in the sequence minus 1.
`#include <dlib/sequence.h>`
Detailed Documentation
Implementations:

> sequence_kernel_1:
> This is implemented as an AVL binary search tree. Accessing(or adding or removing) an element always takes O(log n) time. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for sequence_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

> sequence_kernel_2:
> This implementation is done using a doubly linked list in the shape of a ring. It will remember the last element accessed(or added or removed) and give O(1) access time to the elements just left and right of it. Aside from that, accessing(or adding or removing) a random element will take O(n) and in the worst case it will take time proportional to the size of the sequence/2.

> It does not use the memory_manager at all.

> kernel_2a | is a typedef for sequence_kernel_2
> kernel_2a_c | is a typedef for kernel_2a that checks its preconditions.

# Extensions to sequence

sequence_compare
This extension gives sequences the ability to compare themselves using operator< and operator==. Thus they can be used in the other container classes that require this ability. (maps, sets, etc.)
Detailed Documentation
Implementations:

> sequence_compare_1:
> The implementation is obvious. Click on the sequence_compare_1 link if you want to see.

> compare_1a | is a typedef for sequence_kernel_1a extended by sequence_compare_1
> compare_1a_c | is a typedef for compare_1a that checks its preconditions.
> compare_1b | is a typedef for sequence_kernel_2a extended by sequence_compare_1
> compare_1b_c | is a typedef for compare_1b that checks its preconditions.

sequence_sort
This extension gives a sequence the ability to sort its contents.
Detailed Documentation
Implementations:

> sequence_sort_1:
> This is a version of the QuickSort algorithm and it sorts sequences of less than 30 elements with a selection sort. This implementation is fastest when used with sequence_kernel_2 and fairly slow when used with sequence_kernel_1

> sort_1a | is a typedef for sequence_kernel_2a extended by sequence_sort_1
> sort_1a_c | is a typedef for sort_1a that checks its preconditions.

> sequence_sort_2:
> This is a version of the QuickSort algorithm. This implementation of sort is the best to use with sequence_kernel_1 objects but gives extremely poor performance with sequence_kernel_2 objects.

> sort_2a | is a typedef for sequence_kernel_1a extended by sequence_sort_2
> sort_2a_c | is a typedef for sort_2a that checks its preconditions.

[top]

# set

This object represents an unordered and unaddressed collection of unique items.
`#include <dlib/set.h>`
Detailed Documentation
Implementations:

> set_kernel_1:
> This is implemented using the binary_search_tree component. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for set_kernel_1 that uses binary_search_tree_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.
> kernel_1b | is a typedef for set_kernel_1 that uses binary_search_tree_kernel_2
> kernel_1b_c | is a typedef for kernel_1b that checks its preconditions.

# Extensions to set

set_compare
This extension gives sets the ability to compare themselves using operator< and operator==. Thus they can be used in the other container classes that require this ability. (maps, sets, etc.)
Detailed Documentation
Implementations:

> set_compare_1:
> The implementation is obvious. Click on the set_compare_1 link if you want to see.

> compare_1a | is a typedef for set_kernel_1a extended by set_compare_1
> compare_1a_c | is a typedef for compare_1a that checks its preconditions.
> compare_1b | is a typedef for set_kernel_1b extended by set_compare_1
> compare_1b_c | is a typedef for compare_1b that checks its preconditions.

[top]

# shared_ptr

This object represents a reference counted smart pointer. Each shared_ptr contains a pointer to some object and when the last shared_ptr that points to the object is destructed or reset() then the object is guaranteed to be deleted.

This is an implementation of the std::tr1::shared_ptr template from the document ISO/IEC PDTR 19768, Proposed Draft Technical Report on C++ Library Extensions. The only deviation from that document is that this shared_ptr is declared inside the dlib namespace rather than std::tr1.

`#include <dlib/smart_pointers.h>`
Detailed Documentation
[top]

# shared_ptr_thread_safe

This object represents a reference counted smart pointer just like shared_ptr except that it is threadsafe.

`#include <dlib/smart_pointers_thread_safe.h>`
Detailed Documentation
[top]

# sliding_buffer

This object represents an array with the ability to rotate its contents left or right. Note that the size of this object is always a power of two. If you need arbitrary sized objects then use a circular_buffer.
`#include <dlib/sliding_buffer.h>`
Detailed Documentation
Implementations:

> sliding_buffer_kernel_1:
> This object is implemented using a C style array in the obvious way. See the code for details.

> kernel_1a | is a typedef for sliding_buffer_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

[top]

# stack

This object represents a last in first out stack.
`#include <dlib/stack.h>`
Detailed Documentation
Implementations:

> stack_kernel_1:
> This implementation is done in the obvious way using a singly linked list. It uses the memory_manager for all memory allocations.

> kernel_1a | is a typedef for stack_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

[top]

# static_map

This object represents a mapping of items of type domain onto items of type range. The difference between this object and the normal map object is that it does not support adding or removing individual objects from itself. This allows implementations to focus on using less memory and achieving faster searching.
`#include <dlib/static_map.h>`
Detailed Documentation
Implementations:

> static_map_kernel_1:
> This implementation is just a sorted array which can be searched using a binary search.

> kernel_1a | is a typedef for static_map_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

[top]

# static_set

This object represents an unordered and unaddressed collection of items. The difference between this object and the normal set object is that it does not support adding or removing individual objects from itself. This allows implementations to focus on using less memory and achieving faster searching.
`#include <dlib/static_set.h>`
Detailed Documentation
Implementations:

> static_set_kernel_1:
> This implementation is just a sorted array which can be searched using a binary search.

> kernel_1a | is a typedef for static_set_kernel_1
> kernel_1a_c | is a typedef for kernel_1a that checks its preconditions.

# Extensions to static_set

static_set_compare
This extension gives static_sets the ability to compare themselves using operator< and operator==. Thus they can be used in the other container classes that require this ability. (maps, static_sets, etc.)
Detailed Documentation
Implementations:

> static_set_compare_1:
> The implementation is obvious. Click on the static_set_compare_1 link if you want to see.

> compare_1a | is a typedef for static_set_kernel_1a extended by static_set_compare_1
> compare_1a_c | is a typedef for compare_1a that checks its preconditions.

[top]

# std_vector_c

This object is a simple wrapper around the std::vector object. It provides an identical interface but also checks the preconditions of each member function. That is, if you violate a requires clause the dlib::fatal_error exception is thrown.
`#include <dlib/stl_checked.h>`
Detailed Documentation
[top]

# tuple

This is an implementation of a very simple templated container object. It contains between 0 and 31 objects where each object is listed explicitly in the tuple's template arguments.

Note that there is only one implementation of this object so there aren't any different kernels to choose from when you create instances of the tuple object. So for example, you could declare a tuple of 3 ints using the following statement: `dlib::tuple<int,int,int> t;`

`#include <dlib/tuple.h>`
Detailed Documentation
[top]

# type_safe_union

This object is a type safe analogue of the classic C union object. The type_safe_union, unlike a union, can contain non-POD types such as std::string.

It is also implemented without performing any heap memory allocations and instead it stores everything on the stack.

`#include <dlib/type_safe_union.h>`
Detailed Documentation
C++ Example Programs: pipe_ex_2.cpp, bridge_ex.cpp
[top]

# unordered_pair

This object is very similar to the std::pair struct except unordered_pair is only capable of representing an unordered set of two items rather than an ordered list of two items like std::pair.
`#include <dlib/unordered_pair.h>`
Detailed Documentation
[top]

# weak_ptr

The weak_ptr class template stores a weak reference to an object that is already managed by a shared_ptr. To access the object, a weak_ptr can be converted to a shared_ptr using the member function lock().

This is an implementation of the std::tr1::weak_ptr template from the document ISO/IEC PDTR 19768, Proposed Draft Technical Report on C++ Library Extensions. The only deviation from that document is that this shared_ptr is declared inside the dlib namespace rather than std::tr1.

`#include <dlib/smart_pointers.h>`
Detailed Documentation