The g++ compiler also supports some data structures that are not part of the C++ standard library. Such structures are called policy-based data structures. These data structures are designed for high-performance, flexibility, semantic safety, and conformance to the corresponding containers in std.
To use these structures, the following lines must be added to the code:
For an example following is a code showing a policy-based data structure that is like set, it can add/remove elements, can find the number of elements less than x, kth smallest element etc in O(logn) time. It can also be indexed like an array. The specialty of this set is that we have access to the indices that the elements would have in a sorted array. If the element does not appear in the set, we get the position that the element would have in the set.
The value at 3rd index ::6 The index of number 6::3 The index of number seven ::4
NOTE:Both the functions order_of_key and find_by_order work in logarithmic time.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between C structures and C++ structures
- Structures in C++
- Range-based for loop in C++
- Different types of range-based for loop iterators in C++
- Reversed Range-based for loop in C++ with Examples
- C++ Interview questions based on constructors/ Destructors.
- Difference between fundamental data types and derived data types
- Array of Structures vs. Array within a Structure in C/C++
- C++ Data Types
- std::string::data() in C++
- Static data members in C++
- Initialization of data members
- What is the size_t data type in C?
- vector data() function in C++ STL
- Is there any need of "long" data type in C and C++?
- Bool data type in C++
- Derived Data Types in C++
- array data() in C++ STL with Examples
- How to store Data Triplet in a Vector in C++?
- User defined Data Types in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.