]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*-----------------------------------------------------------------------------+ |
2 | Copyright (c) 2008-2009: Joachim Faulhaber | |
3 | +------------------------------------------------------------------------------+ | |
4 | Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin | |
5 | +------------------------------------------------------------------------------+ | |
6 | Distributed under the Boost Software License, Version 1.0. | |
7 | (See accompanying file LICENCE.txt or copy at | |
8 | http://www.boost.org/LICENSE_1_0.txt) | |
9 | +-----------------------------------------------------------------------------*/ | |
10 | #ifndef BOOST_ICL_VALUE_SIZE_HPP_JOFA_081004 | |
11 | #define BOOST_ICL_VALUE_SIZE_HPP_JOFA_081004 | |
12 | ||
13 | namespace boost{ namespace icl | |
14 | { | |
15 | ||
16 | template <typename Type> | |
17 | Type abs(Type val) { return val < 0 ? -val : val; } | |
18 | ||
19 | /// static class template for the size of a type's value | |
20 | /** This function is needed to be able to order values according | |
21 | to their size. This is used to e.g. prefer simple test | |
22 | instances and to express this simplicity independent of the | |
23 | type of the test case. | |
24 | ||
25 | @author Joachim Faulhaber | |
26 | */ | |
27 | template <class Type> | |
28 | struct value_size | |
29 | { | |
30 | /** The size of a value is used to be able to order values according to | |
31 | their simplicity */ | |
32 | static std::size_t apply(const Type& val); | |
33 | }; | |
34 | ||
35 | ||
36 | template<> inline std::size_t value_size<int>::apply(const int& value) | |
37 | { return abs(value); } | |
38 | ||
39 | template<> inline std::size_t value_size<double>::apply(const double& value) | |
40 | { return static_cast<int>(abs(value)); } | |
41 | ||
42 | template <typename Type> | |
43 | inline std::size_t value_size<Type>::apply(const Type& value) | |
44 | { return icl::iterative_size(value); } | |
45 | ||
46 | ||
47 | ||
48 | }} // namespace boost icl | |
49 | ||
50 | #endif | |
51 | ||
52 |