小编rek*_*lmd的帖子

什么是指定初始化程序?

我想了解指定初始化程序提供的与直接初始化不同的内容。

例如:

#include <iostream>

struct Subject{

    int x;
    int y;
    int z;

};

int main()
{ 
    Subject subject_d{.x = 1, .y = 2, .z= 3};
    Subject subject_c{1, 2, 3};

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我们怎样才能把这两条线剥掉呢?对于细心的人,有什么区别?

c++ designated-initializer c++20

1
推荐指数
1
解决办法
110
查看次数

为什么某些 STL 容器(堆栈、队列、优先级队列)不支持迭代器?

在所有类型的迭代器中,为什么没有支持stack,queue和priority_queueSTL 容器的模式?

#include <iostream>
#include <stack>
#include <algorithm>

int main(){

    std::stack<int> values;
    std::stack<int> valuesCopy;

    values.push(98);
    values.push(11);
    values.push(14);
    values.push(17);
    values.push(20);

    std::for_each( /* How can i manage this in a alternative way */,
                      [&](int value) mutable throw() -> void{ /* Process */ ;} );

    std::copy(/* Same for this */,std::back_inserter(valuesCopy));

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl

0
推荐指数
1
解决办法
102
查看次数

标签 统计

c++ ×2

c++20 ×1

designated-initializer ×1

iterator ×1

stl ×1