build fix
[LibreOffice.git] / include / o3tl / enumrange.hxx
blob5d8c369d30dd93570a0f405e5d7288bbc74a2180
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_O3TL_ENUMRANGE_HXX
21 #define INCLUDED_O3TL_ENUMRANGE_HXX
23 namespace o3tl {
25 ///
26 /// This is a container convenience class iterating over scoped enumerations.
27 ///
28 /// This assumes that the 'enum class' definition
29 /// - starts at zero
30 /// - has no holes in its sequence of values
31 /// - defines a value called LAST which refers to the greatest constant.
32 ///
33 /// Use like this:
34 /// enum class COLOR { RED, GREEN, BLUE, LAST=BLUE };
35 /// for( auto e : o3tl::enumrange<Color>() )
36 /// .....;
37 ///
38 /// \param T the 'enum class' type.
39 template< typename T>
40 class enumrange
42 public:
43 class Iterator
45 public:
46 Iterator( int value ) :
47 m_value( value )
51 T operator*( void ) const
53 return static_cast<T>(m_value);
56 void operator++( void )
58 ++m_value;
61 bool operator!=( Iterator rhs )
63 return m_value != rhs.m_value;
66 private:
67 int m_value;
71 template< typename T >
72 typename enumrange<T>::Iterator begin( enumrange<T> )
74 return typename enumrange<T>::Iterator( (int)0 );
77 template< typename T >
78 typename enumrange<T>::Iterator end( enumrange<T> )
80 return typename enumrange<T>::Iterator( (static_cast<int>(T::LAST)) + 1 );
83 }; // namespace o3tl
85 #endif /* INCLUDED_O3TL_ENUMRANGE_HXX */
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */