CoinUtils trunk
|
00001 /* $Id$ */ 00002 // Copyright (C) 2000, International Business Machines 00003 // Corporation and others. All Rights Reserved. 00004 // This code is licensed under the terms of the Eclipse Public License (EPL). 00005 00006 #ifndef CoinDistance_H 00007 #define CoinDistance_H 00008 00009 #include <iterator> 00010 00011 //------------------------------------------------------------------- 00012 // 00013 // Attempt to provide an std::distance function 00014 // that will work on multiple platforms 00015 // 00016 //------------------------------------------------------------------- 00017 00023 template <class ForwardIterator, class Distance> 00024 void coinDistance(ForwardIterator first, ForwardIterator last, 00025 Distance& n) 00026 { 00027 #if defined(__SUNPRO_CC) 00028 n = 0; 00029 std::distance(first,last,n); 00030 #else 00031 n = std::distance(first,last); 00032 #endif 00033 } 00034 00035 template <class ForwardIterator> 00036 size_t coinDistance(ForwardIterator first, ForwardIterator last) 00037 { 00038 size_t retVal; 00039 #if defined(__SUNPRO_CC) 00040 retVal = 0; 00041 std::distance(first,last,retVal); 00042 #else 00043 retVal = std::distance(first,last); 00044 #endif 00045 return retVal; 00046 } 00047 00048 #endif