Skip to content

Instantly share code, notes, and snippets.

View swkwon's full-sized avatar

Kwon Sangwook swkwon

  • Korea, Republic of
View GitHub Profile
@swkwon
swkwon / decltype_deduction.cpp
Last active November 27, 2017 07:41
decltype type deduction
// ----------------------------------
// example 1
const int i = 0; // decltype(i) is const int
bool f(const Widget& w); // decltype(w) is const Widget&
// decltype(f) is bool(const Widget&)
struct Point {
int x, y; // decltype(Point::x) is int
} // decltype(Point::y) is int
@swkwon
swkwon / type_deduction_in_auto.cpp
Last active November 27, 2017 07:35
type deduction in auto
// ----------------------------------
// example 1
auto x = 26; // x is int
const auto cx = x; // cx is const int
const auto& rx = x; // rx is const int&
auto&& uref1 = x; // uref1 is int&
auto&& uref2 = cx; // uref2 is const int&
auto&& uref3 = 27; // uref3 is int&&
// ----------------------------------
@swkwon
swkwon / typede_duction_in_template.cpp
Last active November 27, 2017 05:15
type deduction in template example
// ----------------------------------
// example 1
template<typename T>
void f(const T& param);
int x = 0;
const int cx = x;
const int& rx = x;
f(x); // param is const int&
f(cx); // param is const int&
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
#pragma once
#include <thread>
#include <future>
#include <iostream>
#include <functional>
class SuspendThread {
private:
std::thread task;
std::promise<void> Psuspend;
public:
#pragma once
#include <thread>
#include <future>
#include <iostream>
class SuspendThread {
private:
std::function<void()> func;
std::thread task;
@swkwon
swkwon / l.cpp
Last active August 29, 2015 14:21
class SuspendThread {
private:
std::thread task;
std::promise<void> Psuspend;
public:
template<typename FN_, typename ... Arguments>
SuspendThread(FN_ func, Arguments&& ... args)
{
auto fut_suspend = Psuspend.get_future();
std::vector<std::function<void()>> fs;
class Widget
{
public:
void get_func()
{
int m = this->member;
fs.emplace_back([m]()
{
std::vector<std::function<void()>> fs;
class Widget
{
public:
void get_func()
{
fs.emplace_back([=]()
{
std::cout << member << std::endl;
void CallbackFunction(std::string& str)
{
auto writeStream = FileOpen('another.txt');
writeStream.write(str);
}
auto readStream = FileOpen('callback.txt');
readStream.ReadEndAsync(CallbackFunction);