元戎启行一面

1,C++11中常用新特性

2,智能指针怎么用的

3,weak_ptr你怎么用(举例)

4,lamba表达式你怎么用的(举例)

5,std::move你怎么用的(举例)

6,给你一个随机生成的不定长的整型数组,求偶数的个数,使用多线程去做(在提示的情况下写出来了)。

#include <iostream>
#include <vector>
#include <thread>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;
int main()
{
    std::vector<int> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 5, 2, 8};
 	int n = 2;
 	int m = data.size() / n;
 	std::vector<std::thread> tds;
 	std::vector<int> res(n, 0);
 	for(int i = 0; i < n; i++) {
        std::function<void(int k)> run_fun = [&](int k){
            int t = 0;
            if(k == n - 1){
                for(int j = k * m; j < data.size(); j++) {
                    if(data[j] % 2 == 0) t++;
                }
            } else {
                for(int j = k * m; j < data.size() && j < (k + 1) * m; j++) {
                    if(data[j] % 2 == 0) t++;
                }
            }
            res[k] = t;
        };
        tds.push_back(std::thread(run_fun, i));
 	}
 	for(int i = 0; i < n; i++) {
        tds[i].join();
 	}
 	std::cout << accumulate(res.begin(), res.end(), 0) << std::endl;
 	return 0;
}

7,Cpu和内存中间还有一层什么

8,一个cache line一般多大

9,cpu缓存一致性

10, 使用模板实现类型对比,比如类名叫IsNameType (没写出来,他帮我写了)

IsNameType<int, int>::value -> true

IsNameType<int, int&>::value -> false

IsNameType<int, A>::value -> false

IsNameType<A, A>::value -> true

#include <iostream>

template<class Type1, class Type2>
struct IsNameType {
    static constexpr bool value = false;
};

template<class Type1>
struct IsNameType<Type1, Type1>{
    static constexpr bool value = true;
};


int main()
{
    std::cout << IsNameType<int, int>::value << std::endl;
    std::cout << IsNameType<int, int&>::value << std::endl;
 	return 0;
}

11,使用模板实现类型类型提取,类名叫RemoveRefence

RemoveRefence<int>::type -> int

RemoveRefence<int&>::type -> int

RemoveRefence<int&&>::type -> int

#include <iostream>

template<class Type1, class Type2>
struct IsNameType {
    static constexpr bool value = false;
};

template<class Type1>
struct IsNameType<Type1, Type1>{
    static constexpr bool value = true;
};

template<class T>
struct RemoveRefence {
    typedef T type;
};

template<class T>
struct RemoveRefence<T&> {
    typedef T type;
};

template<class T>
struct RemoveRefence<T&&> {
    typedef T type;
};

int main()
{
    std::cout << IsNameType<int, int>::value << std::endl;
    std::cout << IsNameType<int, int&>::value << std::endl;
    std::cout << IsNameType<int, RemoveRefence<int&>::type>::value << std::endl;
    std::cout << IsNameType<int, RemoveRefence<int&&>::type>::value << std::endl;
 	return 0;
}

#元戎启行秋招##元戎启行一面#
全部评论
第一次看到考线程手撕的
4 回复 分享
发布于 07-27 11:54 四川
软开吗
1 回复 分享
发布于 07-26 08:51 广东
信也科技
校招火热招聘中
官网直投
感觉好难啊。。。
点赞 回复 分享
发布于 07-26 21:46 湖北

相关推荐

8 95 评论
分享
牛客网
牛客企业服务