|
|
@ -1,133 +1,6 @@
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
|
|
class iterator {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
using value_type = T;
|
|
|
|
|
|
|
|
using size_type = size_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
size_type cursor_;
|
|
|
|
|
|
|
|
const value_type step_;
|
|
|
|
|
|
|
|
value_type value_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iterator(size_type cur_satrt, value_type begin_val, value_type step_val)
|
|
|
|
|
|
|
|
:
|
|
|
|
|
|
|
|
cursor_(cur_satrt),
|
|
|
|
|
|
|
|
step_(step_val),
|
|
|
|
|
|
|
|
value_(begin_val) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value_type operator*() const {
|
|
|
|
|
|
|
|
return value_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(const iterator &rhs) const {
|
|
|
|
|
|
|
|
return (cursor_ != rhs.cursor_);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iterator *operator++() {
|
|
|
|
|
|
|
|
value_ += step_;
|
|
|
|
|
|
|
|
++cursor_;
|
|
|
|
|
|
|
|
return (*this);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void foreach() {
|
|
|
|
|
|
|
|
std::map<std::string, int> mm = {
|
|
|
|
|
|
|
|
{"a", 1},
|
|
|
|
|
|
|
|
{"b", 2},
|
|
|
|
|
|
|
|
{"c", 3}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &m: mm) {
|
|
|
|
|
|
|
|
std::cout << m.first << " -> " << m.second << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int g_constructCount = 0;
|
|
|
|
|
|
|
|
int g_copy_constructCount = 0;
|
|
|
|
|
|
|
|
int g_destructCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class A {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
A() {
|
|
|
|
|
|
|
|
std::cout << "construct: " << ++g_constructCount << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A(const A &a) {
|
|
|
|
|
|
|
|
std::cout << "copy construct: " << ++g_copy_constructCount << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~A() {
|
|
|
|
|
|
|
|
std::cout << "destruct: " << ++g_destructCount << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A getA() {
|
|
|
|
|
|
|
|
return A{};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
|
|
struct GetLeftSize : std::integral_constant<int, 10> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
|
|
|
|
void f(T ... args) {
|
|
|
|
|
|
|
|
std::cout << sizeof...(args) << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
|
|
|
|
void expand(T ... args) {
|
|
|
|
|
|
|
|
std::initializer_list<int>{(std::cout << args << std::endl, 0)...};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename F, typename Arg>
|
|
|
|
|
|
|
|
auto Func(F f, Arg arg) -> decltype(f(arg)) {
|
|
|
|
|
|
|
|
return f(arg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Fn, typename Arg>
|
|
|
|
|
|
|
|
auto GroupBy(const std::vector<Arg> &vt, Fn &&keySelector)
|
|
|
|
|
|
|
|
-> std::multimap<decltype(keySelector((Arg & )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nullptr)), Arg>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef decltype(keySelector(*(Arg * ) nullptr))
|
|
|
|
|
|
|
|
key_type;
|
|
|
|
|
|
|
|
std::multimap<key_type, Arg> map;
|
|
|
|
|
|
|
|
std::for_each(vt
|
|
|
|
|
|
|
|
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
begin(), vt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[&](
|
|
|
|
|
|
|
|
const Arg &arg
|
|
|
|
|
|
|
|
){
|
|
|
|
|
|
|
|
map.
|
|
|
|
|
|
|
|
insert(make_pair(keySelector(arg), arg)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
map;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::mutex g_lock;
|
|
|
|
std::mutex g_lock;
|
|
|
|
|
|
|
|
|
|
|
|
void func() {
|
|
|
|
void func() {
|
|
|
@ -135,15 +8,31 @@ void func() {
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void thread_test() {
|
|
|
|
|
|
|
|
auto start = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
|
|
|
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
|
|
|
std::cout << "start time: " << start / 1000 << std::endl;
|
|
|
|
|
|
|
|
std::thread t0(func);
|
|
|
|
|
|
|
|
std::thread t1(func);
|
|
|
|
|
|
|
|
std::thread t2(func);
|
|
|
|
|
|
|
|
t0.join(); // 阻塞执行
|
|
|
|
|
|
|
|
t1.detach(); // 分离线程何对象,之后就无法何线程发送联系
|
|
|
|
|
|
|
|
t2.join();
|
|
|
|
|
|
|
|
auto end = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
|
|
|
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
|
|
|
std::cout << " end time: " << end / 1000 << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "base/sync_queue.h"
|
|
|
|
#include "base/sync_queue.h"
|
|
|
|
void sync_test(){
|
|
|
|
|
|
|
|
|
|
|
|
void sync_test() {
|
|
|
|
// 同步队列
|
|
|
|
// 同步队列
|
|
|
|
auto queue = new SyncQueue<int>(3);
|
|
|
|
auto queue = new SyncQueue<int>(3);
|
|
|
|
|
|
|
|
|
|
|
|
// 每2秒取出进行消费
|
|
|
|
// 每2秒取出进行消费
|
|
|
|
std::thread producer([&](){
|
|
|
|
std::thread producer([&]() {
|
|
|
|
int i = 0;
|
|
|
|
int i = 0;
|
|
|
|
while (i < 9){
|
|
|
|
while (i < 9) {
|
|
|
|
queue->dequeue(i);
|
|
|
|
queue->dequeue(i);
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
|
std::cout << "dequeue: " << i << std::endl;
|
|
|
|
std::cout << "dequeue: " << i << std::endl;
|
|
|
@ -151,7 +40,7 @@ void sync_test(){
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 持续写入
|
|
|
|
// 持续写入
|
|
|
|
std::thread consumer([&](){
|
|
|
|
std::thread consumer([&]() {
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
queue->enqueue(i);
|
|
|
|
queue->enqueue(i);
|
|
|
|
std::cout << "enqueue: " << i << std::endl;
|
|
|
|
std::cout << "enqueue: " << i << std::endl;
|
|
|
@ -162,59 +51,59 @@ void sync_test(){
|
|
|
|
consumer.join();
|
|
|
|
consumer.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <chrono>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <iomanip>
|
|
|
|
#include "util/stop_watch.h"
|
|
|
|
#include "util/stop_watch.h"
|
|
|
|
|
|
|
|
|
|
|
|
void chrono_test(){
|
|
|
|
void chrono_test() {
|
|
|
|
|
|
|
|
|
|
|
|
StopWatch stopWatch;
|
|
|
|
StopWatch stopWatch;
|
|
|
|
|
|
|
|
|
|
|
|
std::chrono::minutes t1(10);
|
|
|
|
std::chrono::minutes t1(10);
|
|
|
|
std::chrono::seconds t2(60);
|
|
|
|
std::chrono::seconds t2(60);
|
|
|
|
std::chrono::seconds t3 = t1 - t2;
|
|
|
|
std::chrono::seconds t3 = t1 - t2;
|
|
|
|
std::cout << "duration time: " << t3.count() << std::endl;
|
|
|
|
std::cout << "duration time: " << t3.count() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "\ncost time: " << stopWatch.elapsed<std::chrono::microseconds>() << " us\n" << std::endl;
|
|
|
|
std::cout << "\ncost time: " << stopWatch.elapsed<std::chrono::microseconds>() << " us\n" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
|
|
|
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
|
|
|
// 将 time_point 转为 ctime
|
|
|
|
// 将 time_point 转为 ctime
|
|
|
|
std::time_t last = std::chrono::system_clock::to_time_t(now - std::chrono::hours(24));
|
|
|
|
std::time_t last = std::chrono::system_clock::to_time_t(now - std::chrono::hours(24));
|
|
|
|
std::time_t next = std::chrono::system_clock::to_time_t(now + std::chrono::hours (24));
|
|
|
|
std::time_t next = std::chrono::system_clock::to_time_t(now + std::chrono::hours(24));
|
|
|
|
|
|
|
|
|
|
|
|
// 使用put_time格式化时间
|
|
|
|
// 使用put_time格式化时间
|
|
|
|
std::cout
|
|
|
|
std::cout
|
|
|
|
<< "One day ago, the time was "
|
|
|
|
<< "One day ago, the time was "
|
|
|
|
<< std::put_time(std::localtime(&last), "%F %T")
|
|
|
|
<< std::put_time(std::localtime(&last), "%F %T")
|
|
|
|
<< "\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "NExt day ago, the time is "
|
|
|
|
<< "NExt day ago, the time is "
|
|
|
|
<< std::put_time(std::localtime(&next), "%F %T")
|
|
|
|
<< std::put_time(std::localtime(&next), "%F %T")
|
|
|
|
|
|
|
|
|
|
|
|
<< std::endl;
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "\ncost time: " << stopWatch.elapsed() << " ms\n" << std::endl;
|
|
|
|
std::cout << "\ncost time: " << stopWatch.elapsed() << " ms\n" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "base/thread_pool.h"
|
|
|
|
#include "base/thread_pool.h"
|
|
|
|
void thread_test(){
|
|
|
|
|
|
|
|
ThreadPool pool(3,10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::thread t0([&pool]{
|
|
|
|
void threadpool_test() {
|
|
|
|
|
|
|
|
ThreadPool pool(3, 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::thread t0([&pool] {
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
auto thdId = std::this_thread::get_id();
|
|
|
|
auto thdId = std::this_thread::get_id();
|
|
|
|
pool.add([thdId]{
|
|
|
|
pool.add([thdId] {
|
|
|
|
std::cout << "thread 1 id:" << thdId << std::endl;
|
|
|
|
std::cout << "thread 1 id:" << thdId << std::endl;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
std::thread t1([&pool]{
|
|
|
|
std::thread t1([&pool] {
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
auto thdId = std::this_thread::get_id();
|
|
|
|
auto thdId = std::this_thread::get_id();
|
|
|
|
pool.add([thdId]{
|
|
|
|
pool.add([thdId] {
|
|
|
|
std::cout << "thread 2 id:" << thdId << std::endl;
|
|
|
|
std::cout << "thread 2 id:" << thdId << std::endl;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -227,24 +116,24 @@ void thread_test(){
|
|
|
|
t1.join();
|
|
|
|
t1.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "aspect/aspect.h"
|
|
|
|
#include "aspect/aspect.h"
|
|
|
|
#include "test/time_elapsed_aspect.h"
|
|
|
|
#include "test/time_elapsed_aspect.h"
|
|
|
|
#include "test/log_aspect.h"
|
|
|
|
#include "test/log_aspect.h"
|
|
|
|
void HT(int a)
|
|
|
|
|
|
|
|
{
|
|
|
|
void HT(int a) {
|
|
|
|
std::cout << "real HT function " << a << std::endl;
|
|
|
|
std::cout << "real HT function " << a << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void aop_test(){
|
|
|
|
|
|
|
|
|
|
|
|
void aop_test() {
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
aop<LogAspect, TimeElapsedAspect>([](int a){
|
|
|
|
aop<LogAspect, TimeElapsedAspect>([](int a) {
|
|
|
|
std::thread t([a](){
|
|
|
|
std::thread t([a]() {
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
std::cout << "run function, arg is " << a << std::endl;
|
|
|
|
std::cout << "run function, arg is " << a << std::endl;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
t.join();
|
|
|
|
t.join();
|
|
|
|
}, 1);
|
|
|
|
}, 1);
|
|
|
|
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
|
|
|
@ -252,41 +141,140 @@ void aop_test(){
|
|
|
|
aop<LogAspect>(f, 100);
|
|
|
|
aop<LogAspect>(f, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
// 同步队列测试
|
|
|
|
|
|
|
|
// sync_test();
|
|
|
|
|
|
|
|
// 时间工具测试
|
|
|
|
|
|
|
|
// chrono_test();
|
|
|
|
|
|
|
|
// 线程池测试
|
|
|
|
|
|
|
|
// thread_test();
|
|
|
|
|
|
|
|
// AOP测试
|
|
|
|
|
|
|
|
aop_test();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "base/any.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void any_test() {
|
|
|
|
|
|
|
|
Any n;
|
|
|
|
|
|
|
|
auto r = n.IsNull();//true
|
|
|
|
|
|
|
|
string s1 = "hello";
|
|
|
|
|
|
|
|
n = s1;
|
|
|
|
|
|
|
|
n = "world";
|
|
|
|
|
|
|
|
n.AnyCast<int>(); //can not cast int to string
|
|
|
|
|
|
|
|
Any n1 = 1;
|
|
|
|
|
|
|
|
n1.Is<int>(); //true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ioc/container.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ioc_test() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Base {
|
|
|
|
|
|
|
|
virtual ~Base() = default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void Func() = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct DerivedB : public Base {
|
|
|
|
|
|
|
|
DerivedB(int a, double b) : m_a(a), m_b(b) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~DerivedB() override = default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Func() override {
|
|
|
|
|
|
|
|
cout << "DerivedB run :" << m_a + m_b << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
int m_a;
|
|
|
|
|
|
|
|
double m_b;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct DerivedC : public Base {
|
|
|
|
|
|
|
|
~DerivedC() override = default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Func() override {
|
|
|
|
|
|
|
|
std::cout << "DerivedC " << std::endl;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
|
|
|
|
A(Base *ptr) : m_ptr(ptr) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~A() {
|
|
|
|
|
|
|
|
if (m_ptr != nullptr) {
|
|
|
|
|
|
|
|
delete m_ptr;
|
|
|
|
|
|
|
|
m_ptr = nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Func() {
|
|
|
|
|
|
|
|
m_ptr->Func();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Base *m_ptr;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IocContainer ioc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO 可通过CRTP奇怪的重复模板模式进行自动注册
|
|
|
|
|
|
|
|
|
|
|
|
// auto start = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
// 注册依赖关系
|
|
|
|
// std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
ioc.RegisterType<A, DerivedC>("C");
|
|
|
|
// std::cout << "start time: " << start / 1000 << std::endl;
|
|
|
|
ioc.RegisterType<A, DerivedB, int, double>("B");
|
|
|
|
// std::thread t0(func);
|
|
|
|
|
|
|
|
// std::thread t1(func);
|
|
|
|
// 通过容器进行初始化
|
|
|
|
// std::thread t2(func);
|
|
|
|
auto pc = ioc.ResolveShared<A>("C");
|
|
|
|
// t0.join(); // 阻塞执行
|
|
|
|
// 注意DerivedB的参数int,double
|
|
|
|
// t1.detach(); // 分离线程何对象,之后就无法何线程发送联系
|
|
|
|
auto pb = ioc.ResolveShared<A>("B", 1, 2.0);
|
|
|
|
// t2.join();
|
|
|
|
|
|
|
|
// auto end = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
pc->Func();
|
|
|
|
// std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
pb->Func();
|
|
|
|
// std::cout << " end time: " << end / 1000 << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A&& a = getA();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// expand(1,2,3,4);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// std::cout << GetLeftSize<int>::value << std::endl;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// f();
|
|
|
|
|
|
|
|
// f(1);
|
|
|
|
|
|
|
|
// f(1,2.5,"");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// foreach();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "bus/message_bus.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void message_test() {
|
|
|
|
|
|
|
|
MessageBus bus;
|
|
|
|
|
|
|
|
//注册消息
|
|
|
|
|
|
|
|
bus.Attach([](int a) { cout << "no reference: " << a << endl; });
|
|
|
|
|
|
|
|
bus.Attach([](int &a) { cout << "lvalue reference: " << a << endl; });
|
|
|
|
|
|
|
|
bus.Attach([](int &&a) { cout << "rvalue reference: " << a << endl; });
|
|
|
|
|
|
|
|
bus.Attach([](const int &a) { cout << "const lvalue reference: " << a << endl; });
|
|
|
|
|
|
|
|
bus.Attach([](int a) {
|
|
|
|
|
|
|
|
cout << "no reference has return value and key: " << a << endl;
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
|
|
|
}, "a");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i = 2;
|
|
|
|
|
|
|
|
bus.SendReq<void, int>(2);
|
|
|
|
|
|
|
|
bus.SendReq<int, int>(2, "a");
|
|
|
|
|
|
|
|
bus.SendReq<void, int &>(i);
|
|
|
|
|
|
|
|
bus.SendReq<void, const int &>(2);
|
|
|
|
|
|
|
|
bus.SendReq<void, int &&>(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bus.Remove<void, int>();
|
|
|
|
|
|
|
|
bus.Remove<int, int>("a");
|
|
|
|
|
|
|
|
bus.Remove<void, int &>();
|
|
|
|
|
|
|
|
bus.Remove<void, const int &>();
|
|
|
|
|
|
|
|
bus.Remove<void, int &&>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bus.SendReq<void, int>(2);
|
|
|
|
|
|
|
|
bus.SendReq<int, int>(2, "a");
|
|
|
|
|
|
|
|
bus.SendReq<void, int &>(i);
|
|
|
|
|
|
|
|
bus.SendReq<void, const int &>(2);
|
|
|
|
|
|
|
|
bus.SendReq<void, int &&>(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
// 线程测试
|
|
|
|
|
|
|
|
thread_test();
|
|
|
|
|
|
|
|
// 同步队列测试
|
|
|
|
|
|
|
|
sync_test();
|
|
|
|
|
|
|
|
// 时间工具测试
|
|
|
|
|
|
|
|
chrono_test();
|
|
|
|
|
|
|
|
// 线程池测试
|
|
|
|
|
|
|
|
threadpool_test();
|
|
|
|
|
|
|
|
// AOP测试
|
|
|
|
|
|
|
|
aop_test();
|
|
|
|
|
|
|
|
// Any测试
|
|
|
|
|
|
|
|
any_test();
|
|
|
|
|
|
|
|
// IoC测试
|
|
|
|
|
|
|
|
ioc_test();
|
|
|
|
|
|
|
|
// 总线测试
|
|
|
|
|
|
|
|
message_test();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|