1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
26 /// This is a container convenience class iterating over scoped enumerations.
28 /// This assumes that the 'enum class' definition
30 /// - has no holes in its sequence of values
31 /// - defines a value called LAST which refers to the greatest constant.
34 /// enum class COLOR { RED, GREEN, BLUE, LAST=BLUE };
35 /// for( auto e : o3tl::enumrange<Color>() )
38 /// \param T the 'enum class' type.
46 Iterator( int value
) :
51 T
operator*( void ) const
53 return static_cast<T
>(m_value
);
56 void operator++( void )
61 bool operator!=( Iterator rhs
)
63 return m_value
!= rhs
.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 );
85 #endif /* INCLUDED_O3TL_ENUMRANGE_HXX */
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */