C++ “方形列表”;比较构造函数“;实施

C++ “方形列表”;比较构造函数“;实施,c++,boost,constructor,C++,Boost,Constructor,对于家庭作业,我必须实现一个方形列表(已经完成),并通过所有提供的单元测试。除了一个和这个特定的单元测试外,我已经通过了“比较构造函数”实现的所有测试 以下是所涉及的增压单元测试: #include "ut_square_list.hpp" #include <boost\test\auto_unit_test.hpp> #include <vector> using std::vector; template <class T> class Runtime

对于家庭作业,我必须实现一个方形列表(已经完成),并通过所有提供的单元测试。除了一个和这个特定的单元测试外,我已经通过了“比较构造函数”实现的所有测试

以下是所涉及的增压单元测试:

#include "ut_square_list.hpp"
#include <boost\test\auto_unit_test.hpp>
#include <vector>
using std::vector;

template <class T>
class RuntimeCmp
{
public:
    enum cmp_mode { normal, reverse };
private:
    cmp_mode mode;
public:
    RuntimeCmp( cmp_mode m = normal ) : mode(m) { } // constructor
    bool operator()(T const& t1, T const& t2) const { return mode == normal ? t1 < t2 : t2 < t1; } // function call operator - 
    bool operator==( RuntimeCmp const& rc ) { return mode == rc.mode; }
};



/** Test square_list<T>::square_list() */
BOOST_AUTO_TEST_CASE( ut_ctor_compare_def ) {
    square_list<double,RuntimeCmp<double>> s;
    vector<double> data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

    for (auto x : data)
        s.insert(x);

    BOOST_CHECK( std::equal( s.begin(), s.end(), data.begin() ) );
}



BOOST_AUTO_TEST_CASE( ut_ctor_compare_passed ) {
    RuntimeCmp<double> rc(RuntimeCmp<double>::reverse);
    square_list<double,RuntimeCmp<double>> s(rc);
    vector<double> data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };


    for (auto x : data)
        s.insert(x);

    BOOST_CHECK( std::equal( s.begin(), s.end(), data.rbegin() ) );
}



BOOST_AUTO_TEST_CASE( ut_ctor_compare_iterator_passed ) {
    vector<double> data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    RuntimeCmp<double> rc(RuntimeCmp<double>::reverse);
    square_list<double,RuntimeCmp<double>> s(data.begin(),data.end(),rc);

    BOOST_CHECK( std::equal( s.begin(), s.end(), data.rbegin() ) );
}
#包括“ut_square_list.hpp”
#包括
#包括
使用std::vector;
模板
类运行时CMP
{
公众:
枚举cmp_模式{正常,反向};
私人:
cmp_模式;
公众:
RuntimeCmp(cmp_mode m=normal):模式(m){}//构造函数
bool操作符()(T const&t1,T const&t2)const{return mode==normal?t1

基于上述内容的“比较构造函数”是什么?我搞不懂。

根据您提供的上下文,我认为“比较构造函数”是指将比较对象作为参数的构造函数


“默认构造函数”或“复制构造函数”等术语是特定于语言的,而“比较构造函数”则不是。这是专门针对这个家庭作业的。

从您给出的上下文来看,我认为“比较构造函数”是指将比较对象作为参数的构造函数


“默认构造函数”或“复制构造函数”等术语是特定于语言的,而“比较构造函数”则不是。这是专门针对这个家庭作业的。

这一行怎么样:BOOST_CHECK(std::equal(s.begin()、s.end()、data.rbegin());“这有什么意义?”Bojs问这是什么意思。这意味着当使用模式
reverse
RuntimeCmp
实例初始化
s
时,
s
的顺序会颠倒。这一行怎么样:BOOST_CHECK(std::equal(s.begin(),s.end(),data.rbegin());“这有什么意义?”Bojs问这是什么意思。这意味着当使用模式
reverse
RuntimeCmp
实例初始化
s
时,
s
的顺序会颠倒。这一行怎么样:BOOST_CHECK(std::equal(s.begin(),s.end(),data.rbegin());“这有什么意义?”Bojs问这是什么意思。这意味着当
s
使用模式
reverse
RuntimeCmp
实例初始化时,
s
的顺序颠倒。