This section lists several miscelaneous utility types and functions not
related directly to work with OpenGL, but used by other parts of OGLplus
and also utilities that are not included by oglplus/all.hpp
,
but can be optionally included and used by the library end-users.
#include
<oglplus/utils/nothing.hpp>
Nothing
is a nullary Metafunction
returning itself, which serves as a nil type in
OGLplus.
struct Nothing { typedef Nothing Type; };
#include
<oglplus/opt/ranges.hpp>
This header implements utilities for working with types conforming to the Range concept.
All range-related utilities are implemented in the oglplus::ranges
namespace:
namespace ranges {
IsRange
The IsRange
boolean Metafunction
allows to check if a type conforms to the Range
concept:
template <typename Range> struct IsRange { typedef <Unspecified> Type; };
|
AnyRange
The AnyRange
template is a type erasure for all types
conforming to Range<Element>
- i.e. a range whose element type is implicitly convertible to the Element
type template parameter of AnyRange
. AnyRange
is typically used as a parameter type for functions implementing complex
range algorithms.
template <typename Element> class AnyRange { public: AnyRange(void); template <typename Range> AnyRange(Range range); template <typename Range> AnyRange& operator = (const Range& range); AnyRange(const AnyRange& other); AnyRange(AnyRange&& temp); AnyRange& operator = (const AnyRange& other); AnyRange& operator = (AnyRange&& other); typedef Element ValueType; bool Empty(void) const; size_t Size(void) const; void Next(void); ValueType Front(void) const; }; template <typename Range> AnyRange<typename Range::ValueType> EraseType(Range range);
Construction and assignment from a |
|
Copy and move construction. |
|
Copy and move assignment. |
|
The Range interface. |
|
Erases the real type of the range passed as argument. |
The following functions traverse, filter of modify ranges and can be easily composed into complex algorithms.
template <typename Range> Range Find(Range range, typename Range::ValueType value); template <typename Range, typename Predicate> Range FindIf(Range range, Predicate predicate) template <typename Range> bool Contains(Range range, typename Range::ValueType value); template <typename Range, typename Predicate> bool Has(Range range, Predicate predicate); template <typename Range, typename Transf> Range Transform(Range range, Transf transform); template <typename Range, typename State, typename Func> State Fold(Range range, State state, Func functor); template <typename Range, typename Predicate> size_t CountIf(Range range, Predicate predicate); template <typename Range, typename Predicate> Range OnlyIf(Range range, Predicate pred); template <typename Element, typename R1, typename R2> Range Concatenate(R1 r1, R2 r2);
Traverses a range and stops either if the range is empty or if the specified value is found. The resulting range is returned. |
|
Finds the first a value satisfying a predicate in a range. This function traverses a range and stops either if the range is empty or if a value satisfying the predicate is found. The resulting range is returned. |
|
Returns true if |
|
Returns true if |
|
Transforms the elements in a range by an unary function. |
|
Folds a |
|
Counts and returns the number of elements in a Range
satisfying the specified |
|
The |
|
Returns a range that is a concatenation of the ranges |
} // namespace ranges
Print the value names of all values in the ObjectType
and the ShaderType
enumerations to the standard output.
using namespace oglplus::ranges; ForEach( Concatenate<StrCRef>( Transform(EnumValueRange<ObjectType>(), EnumValueName<ObjectType>), Transform(EnumValueRange<ShaderType>(), EnumValueName<ShaderType>) ), [](StrCRef str) { std::cout << str << std::endl; } );
Check if the GL_EXT_direct_state_access
extension
is implemented.
using namespace oglplus::ranges; Context gl; if(Contains(gl.Extensions(), "GL_EXT_direct_state_access")) { std::cout << "Yay! We have DSA." << std::endl; }
Print the number of ARB
GL extensions.
using namespace oglplus::ranges; Context gl; std::cout << CountIf( gl.Extensions(), [](const std::string& ext) -> bool { return ext.find("_ARB_") != std::string::npos; } ) << std::endl;
Print the GL extension with the longest name.
using namespace oglplus::ranges; typedef std::pair<std::size_t, std::string> length_and_name; Context gl; std::cout << Fold( gl.Extensions(), length_and_name(0, "N/A"), [](length_and_name state, std::string ext) -> length_and_name { if(state.first < ext.length()) { state.first = ext.length(); state.second = std::move(ext); } return state; } ).second << std::endl;