相关疑难解决方法(0)

为什么在C++中没有排序(v)?

我总是想知道为什么没有

sort(v);// same as std::sort(v.begin(),v.end())
Run Code Online (Sandbox Code Playgroud)

如果我很久以前回想起来的话,我看到了一个boostcon剪辑,其中说话者说这需要概念,但我不明白为什么.顺便说一句,我试过这个(在VS 11中)并且它从我能看到的内容中起作用.

template <typename Container>
void sortfx(Container& c)
{
    std::sort(c.begin(),c.end());
}
int main()
{

    std::vector<double> v;
    //std::list<double> v; this causes compile errors
    v.push_back(1701);
    v.push_back(1729);
    v.push_back(74656);
    v.push_back(2063);
    sortfx(v);
    assert(std::is_sorted(begin(v),end(v)));

}
Run Code Online (Sandbox Code Playgroud)

编辑:Bjarne自己解释了概念,以排序为例:) https://www.informit.com/articles/article.aspx?p=2080042&WT.rss_f=Article&WT.rss_a=An%20Interview%20with%20Bjarne%20Stroustrup&WT .rss_ev =一

c++ stl

11
推荐指数
2
解决办法
512
查看次数

标签 统计

c++ ×1

stl ×1