代码适用于VS2010,但不适用于VC ++ 6.0

时间:2013-05-25 22:29:32

标签: c++ visual-c++ iterator stemming

我正在开发一个项目,我正在使用词干库,它在Visual Studio 2010(Express)上非常完美,但是当我尝试在VC ++ 6.0中编译同一个项目时,它会产生错误。我修了几个,但我被困在了一些。我认为与模板相关的东西......

出于某种原因,我需要在VC 6.0中执行此操作。

以下是该文件的完整代码:

/***************************************************************************
                          utilities.h  -  description
                             -------------------
    begin                : Sat Apr 26 2003
    copyright            : (C) 2003 by Blake Madden
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the BSD License.                                *
 *                                                                         *
 ***************************************************************************/

#ifndef __UTILITIES_H__
#define __UTILITIES_H__

#include <algorithm>
#include <functional>
#include <math.h>
#include <cassert>
#include <iterator>

#ifndef M_PI
    #define M_PI 3.1415926535897932384626433832795
#endif

//returns the byte size of an array
#define size_of_array(x) (sizeof(x)/sizeof(x[0]))

inline double within_range(size_t start, size_t end, double value)
    {
    return ( (value >= start) && (value <= end) ) ? value :
            (value < start) ? start :
            (value > end) ? end : /*never reaches this branch*/ value;
    }

inline float degrees_to_radians(const float degrees)
    { return degrees * (M_PI/static_cast<float>(180)); }

//Opposite side is the side going upwards of a right triangle
inline float calc_opposite_side(const float hypontenuse, const float angleInDegrees)
    {
    return (sin(degrees_to_radians(angleInDegrees)) * hypontenuse);
    }

//Adjacent side is the side at the bottom of a right triangle
inline float calc_adjacent_side(const float hypontenuse, const float angleInDegrees)
    {
    return (cos(degrees_to_radians(angleInDegrees)) * hypontenuse);
    }

//Function to see if a number is even
template<typename T>
inline bool is_even(T value)
    { return (value%2) == 0; }
//specialized version of is_even for floating point value types that need to be "floored" first
inline bool is_even(double value)
    { return (static_cast<long>(floor(abs(value)))%2) == 0; }
inline bool is_even(float value)
    { return (static_cast<long>(floor(abs(value)))%2) == 0; }

///integer rounding function
template<typename T>
inline double round(T x)
    { return (floor(x+0.5f)); }

//class that remembers its original value from constuction
template <typename T>
class backup_variable
    {
public:
    backup_variable(const T& value) : m_originalValue(value), m_value(value)
        {}
    void operator=(const T& value)
        { m_value = value; }
    bool operator==(const T& value) const
        { return m_value == value; }
    bool operator<(const T& value) const
        { return m_value < value; }
    bool operator<=(const T& value) const
        { return m_value <= value; }
    bool operator>(const T& value) const
        { return m_value > value; }
    bool operator>=(const T& value) const
        { return m_value >= value; }
    void operator+(const T& value)
        { m_value + value; }
    void operator+=(const T& value)
        { m_value += value; }
    void operator-(const T& value)
        { m_value - value; }
    void operator-=(const T& value)
        { m_value -= value; }
    operator const T() const
        { return m_value; }
    T* operator&()
        { return &m_value; }
    T get_value() const
        { return m_value; }
    bool has_changed() const
        { return m_value != m_originalValue; }
private:
    T m_originalValue;
    T m_value;
    };

template<typename T>
inline bool is_either(T value, T first, T second)
    {
    return (value == first || value == second);
    }

template<typename T>
inline bool is_neither(T value, T first, T second)
    {
    assert(first != second);
    return (value != first && value != second);
    }

template<typename T>
inline bool is_within(T value, T first, T second)
    {
    assert(first <= second);
    return (value >= first && value <= second);
    }

/*calls a member function of elements in a container for each
elelement in another container*/
template<typename inT, typename outT, typename member_extract_functorT>
inline outT copy_member(inT begin, inT end, outT dest, member_extract_functorT get_value)
    {
    for (; begin != end; ++dest, ++begin)
        *dest = get_value(*begin);
    return (dest);
    }

template<typename inT, typename outT,
         typename _Pr,
         typename member_extract_functorT>
inline outT copy_member_if(inT begin, inT end, outT dest,
                           _Pr meets_criteria,
                           member_extract_functorT get_value)
    {
    for (; begin != end; ++begin)
        {
        if (meets_criteria(*begin))
            {
            *dest = get_value(*begin);
            ++dest;
            }
        }
    return (dest);
    }

template<typename _InIt, typename _Pr, typename member_extract_functorT>
inline typename std::iterator_traits<_InIt>::difference_type
    count_member_if(_InIt _First, _InIt _Last,
                    _Pr _Pred, member_extract_functorT get_value)
    {
    //count elements satisfying _Pred
    typename std::iterator_traits<_InIt>::difference_type _Count = 0;

    for (; _First != _Last; ++_First)
        if (_Pred(get_value(*_First)) )
            ++_Count;
    return (_Count);
    }

//determines if number is even
template <typename T>
class even : public std::unary_function<T, bool>
    {
public:
    inline bool operator()(const T& val) const
        { return val%2==0; }
    };

//determines if a value is within a given range
template<typename T>
class within : public std::unary_function<T, bool>
    {
public:
    within(T range_begin, T range_end)
        : m_range_begin(range_begin), m_range_end(range_end)
        {}
    inline bool operator()(T value) const
        { return (value >= m_range_begin && value <= m_range_end); }
private:
    T m_range_begin;
    T m_range_end;
    };

#endif //__UTILITIES_H__

这是错误列表:

Compiling...
main.cpp
c:\[path]\utilities.h(158) : error C2039: 'difference_type' : is not a member of 'iterator_traits<_It>'
c:\[path]\utilities.h(158) : error C2146: syntax error : missing ';' before identifier 'count_member_if'
c:\[path]\utilities.h(158) : error C2433: 'difference_type' : 'inline' not permitted on data declarations
c:\[path]\utilities.h(158) : error C2501: 'difference_type' : missing storage-class or type specifiers
c:\[path]\utilities.h(158) : error C2059: syntax error : ';'
c:\[path]\utilities.h(158) : error C2065: '_InIt' : undeclared identifier
c:\[path]\utilities.h(158) : error C2146: syntax error : missing ')' before identifier '_First'
c:\[path]\utilities.h(158) : error C2501: 'count_member_if' : missing storage-class or type specifiers
c:\[path]\utilities.h(159) : error C2059: syntax error : ')'
c:\[path]\utilities.h(180) : error C2954: template definitions cannot nest
c:\[path]\utilities.h(185) : error C2065: 'm_range_begin' : undeclared identifier
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(185) : error C2065: 'range_begin' : undeclared identifier
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(185) : error C2461: 'within<T>' : constructor syntax missing formal parameters
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(185) : error C2061: syntax error : identifier 'range_end'
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(186) : error C2143: syntax error : missing ';' before '{'
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(186) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(188) : error C2059: syntax error : 'return'
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(188) : error C2238: unexpected token(s) preceding ';'
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled
c:\[path]\utilities.h(189) : error C2143: syntax error : missing ';' before 'private'
c:\[path]\utilities.h(192) : see reference to class template instantiation 'within<T>' being compiled

我会感谢任何帮助/线索。

0 个答案:

没有答案