Main Page
Namespaces
Classes
Files
File List
File Members
include
LowLevel
GteRangeIteration.h
Go to the documentation of this file.
1
// David Eberly, Geometric Tools, Redmond WA 98052
2
// Copyright (c) 1998-2017
3
// Distributed under the Boost Software License, Version 1.0.
4
// http://www.boost.org/LICENSE_1_0.txt
5
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6
// File Version: 3.0.0 (2016/06/19)
7
8
#pragma once
9
10
#include <
GTEngineDEF.h
>
11
#include <iterator>
12
#include <type_traits>
13
14
// For information on range-based for-loops, see
15
// http://en.cppreference.com/w/cpp/language/range-for
16
17
namespace
gte
18
{
19
20
// The function gte::reverse supports reverse iteration in range-based
21
// for-loops using the auto keyword. For example,
22
//
23
// std::vector<int> numbers(4);
24
// int i = 0;
25
// for (auto& number : numbers)
26
// {
27
// number = i++;
28
// std::cout << number << ' ';
29
// }
30
// // Output: 0 1 2 3
31
//
32
// for (auto& number : gte::reverse(numbers))
33
// {
34
// std::cout << number << ' ';
35
// }
36
// // Output: 3 2 1 0
37
38
template
<
typename
Iterator>
39
class
ReversalObject
40
{
41
public
:
42
ReversalObject
(Iterator
begin
, Iterator
end
)
43
:
44
mBegin
(begin),
45
mEnd
(end)
46
{
47
}
48
49
Iterator
begin
()
const
{
return
mBegin
; }
50
Iterator
end
()
const
{
return
mEnd
; }
51
52
private
:
53
Iterator
mBegin
,
mEnd
;
54
};
55
56
template
57
<
58
typename
Iterable,
59
typename
Iterator = decltype(std::begin(std::declval<Iterable>())),
60
typename
ReverseIterator = std::reverse_iterator<Iterator>
61
>
62
ReversalObject<ReverseIterator>
reverse
(Iterable&&
range
)
63
{
64
return
ReversalObject<ReverseIterator>
(
65
ReverseIterator(
std::end
(
range
)),
66
ReverseIterator(std::begin(
range
)));
67
}
68
69
}
gte::reverse
ReversalObject< ReverseIterator > reverse(Iterable &&range)
Definition:
GteRangeIteration.h:62
GTEngineDEF.h
gte::ReversalObject::mEnd
Iterator mEnd
Definition:
GteRangeIteration.h:53
end
GLuint GLuint end
Definition:
glcorearb.h:470
gte
Definition:
GLX/GteWICFileIO.h:16
gte::ReversalObject
Definition:
GteRangeIteration.h:39
gte::ReversalObject::begin
Iterator begin() const
Definition:
GteRangeIteration.h:49
gte::ReversalObject::end
Iterator end() const
Definition:
GteRangeIteration.h:50
range
GLenum GLint * range
Definition:
glcorearb.h:1920
gte::ReversalObject::mBegin
Iterator mBegin
Definition:
GteRangeIteration.h:53
gte::ReversalObject::ReversalObject
ReversalObject(Iterator begin, Iterator end)
Definition:
GteRangeIteration.h:42
geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01