1/* $Id: CoinDistance.hpp 1372 2011-01-03 23:31:00Z lou $ */
2// Copyright (C) 2000, International Business Machines
3// Corporation and others. All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef CoinDistance_H
7#define CoinDistance_H
8
9#include <iterator>
10
11//-------------------------------------------------------------------
12//
13// Attempt to provide an std::distance function
14// that will work on multiple platforms
15//
16//-------------------------------------------------------------------
17
18/** CoinDistance
19
20This is the Coin implementation of the std::function that is
21designed to work on multiple platforms.
22*/
23template <class ForwardIterator, class Distance>
24void coinDistance(ForwardIterator first, ForwardIterator last,
25 Distance& n)
26{
27#if defined(__SUNPRO_CC)
28 n = 0;
29 std::distance(first,last,n);
30#else
31 n = std::distance(first,last);
32#endif
33}
34
35template <class ForwardIterator>
36size_t coinDistance(ForwardIterator first, ForwardIterator last)
37{
38 size_t retVal;
39#if defined(__SUNPRO_CC)
40 retVal = 0;
41 std::distance(first,last,retVal);
42#else
43 retVal = std::distance(first,last);
44#endif
45 return retVal;
46}
47
48#endif
49