[C++ Korea] Effective Modern C++ Study item14 16 +신촌Seok-joon Yun
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
Item 14 : Declare functions noexcept if they won't emit exceptions. +윤석준
Item 15 : Use constexpr whenever possible. +이동우
Item 16 : Make const member functions thread safe. +제한재
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23Seok-joon Yun
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23
Item 20, 21, 23
Item 20 : Use std::weak_ptr for std::shared_ptr-like pointers that can dangle. +정은식
Item 21 : Prefer std::make_unique and std::make_shared to direct use of new. +이동우
Item 23 : Understand std::move and std::forward. +제한재
[C++ Korea] Effective Modern C++ Study item14 16 +신촌Seok-joon Yun
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
Item 14 : Declare functions noexcept if they won't emit exceptions. +윤석준
Item 15 : Use constexpr whenever possible. +이동우
Item 16 : Make const member functions thread safe. +제한재
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23Seok-joon Yun
[C++ korea] Effective Modern C++ 신촌 Study Item20,21,23
Item 20, 21, 23
Item 20 : Use std::weak_ptr for std::shared_ptr-like pointers that can dangle. +정은식
Item 21 : Prefer std::make_unique and std::make_shared to direct use of new. +이동우
Item 23 : Understand std::move and std::forward. +제한재
[C++ Korea] Effective Modern C++ Study item 24-26Seok-joon Yun
[C++ Korea] Effective Modern C++ Study item 24-26
Item 24: Distinguish universal references from rvalue references. +석정로
Item 25 : Use std::move on rvalue references,
std::forward on universal references. +서승덕
Item 26 : Avoid overloading on universal references. +윤석준
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기Chris Ohk
기존에 작성해 놓은 C++ 코드에 모던 C++를 적용하기는 쉽지 않습니다. 막상 개선하려고 마음먹었다고 해도, 어디서부터 바꿔야 할 지 막막하기만 합니다. 이 세션에서는 기존 C++ 코드에서 모던 C++를 적용해 프로그램의 구조와 성능을 개선하는 방법에 대해서 설명합니다. 그리고 기존 C++ 코드에 모던 C++를 적용할 때 주의해야 될 점에 대해서도 살펴봅니다.
[C++ Korea 2nd Seminar] C++17 Key Features SummaryChris Ohk
C++은 10년 만에 C++11/14를 발표하면서 '모던 C++'이라는 이름으로 발전했습니다. 그만큼 새로운 기능들이 많이 추가되었습니다. 그리고 2017년, C++은 C++17이라는 이름으로 또 한 번의 발전을 준비하고 있습니다. 3년 주기로 빠르게 변화하는 모던 C++에 대비하기 위해, C++17에 추가될 주요 기능들을 살펴보고자 합니다.
C++은 10년 만에 C++11/14를 발표하면서 '모던 C++'이라는 이름으로 발전했습니다. 그만큼 새로운 기능들이 많이 추가되었습니다. 그리고 2017년, C++은 C++17이라는 이름으로 또 한 번의 발전을 준비하고 있습니다. 3년 주기로 빠르게 변화하는 모던 C++에 대비하기 위해, C++17에 추가될 주요 기능들을 살펴보고자 합니다.
이 발표는 이전에 발표했던 내용에서 일부 사례 추가 및 최신 내용으로 갱신한 버전입니다.
[C++ Korea] Effective Modern C++ Study item 24-26Seok-joon Yun
[C++ Korea] Effective Modern C++ Study item 24-26
Item 24: Distinguish universal references from rvalue references. +석정로
Item 25 : Use std::move on rvalue references,
std::forward on universal references. +서승덕
Item 26 : Avoid overloading on universal references. +윤석준
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기Chris Ohk
기존에 작성해 놓은 C++ 코드에 모던 C++를 적용하기는 쉽지 않습니다. 막상 개선하려고 마음먹었다고 해도, 어디서부터 바꿔야 할 지 막막하기만 합니다. 이 세션에서는 기존 C++ 코드에서 모던 C++를 적용해 프로그램의 구조와 성능을 개선하는 방법에 대해서 설명합니다. 그리고 기존 C++ 코드에 모던 C++를 적용할 때 주의해야 될 점에 대해서도 살펴봅니다.
[C++ Korea 2nd Seminar] C++17 Key Features SummaryChris Ohk
C++은 10년 만에 C++11/14를 발표하면서 '모던 C++'이라는 이름으로 발전했습니다. 그만큼 새로운 기능들이 많이 추가되었습니다. 그리고 2017년, C++은 C++17이라는 이름으로 또 한 번의 발전을 준비하고 있습니다. 3년 주기로 빠르게 변화하는 모던 C++에 대비하기 위해, C++17에 추가될 주요 기능들을 살펴보고자 합니다.
C++은 10년 만에 C++11/14를 발표하면서 '모던 C++'이라는 이름으로 발전했습니다. 그만큼 새로운 기능들이 많이 추가되었습니다. 그리고 2017년, C++은 C++17이라는 이름으로 또 한 번의 발전을 준비하고 있습니다. 3년 주기로 빠르게 변화하는 모던 C++에 대비하기 위해, C++17에 추가될 주요 기능들을 살펴보고자 합니다.
이 발표는 이전에 발표했던 내용에서 일부 사례 추가 및 최신 내용으로 갱신한 버전입니다.
모던 C++의 시초인 C++11은 C++ 코드 전반에 많은 변화를 가져왔습니다. 그리고 최근 C++20의 표준위원회 회의가 마무리되었습니다. 내년에 C++20이 도입되면 C++11이 처음 도입되었을 때와 비슷한 규모, 또는 그 이상의 변화가 있을 것이라고 예상하고 있습니다. C++20에는 Concepts, Contract, Ranges, Coroutine, Module 등 굵직한 기능 외에도 많은 기능들이 추가될 예정입니다. 이번 세션에서는 C++20에 추가될 주요 기능들을 살펴보고자 합니다.
2. C++11
오랫동안 C++0x로 알려졌었다.
하지만 2010년이 되어버렸긔…
0x는 16진수라 2015년까진 나올꺼란 드립이 나옴
올해 스펙이 확정되면서 C++11로 확정
많은 변화가 있지만
오늘 살펴볼 내용은
http://www.softwarequalityconnection.com/2011/06/th
e-biggest-changes-in-c11-and-why-you-should-care/
를 정리한 내용입니다.
3. C++11
New Algorithms
New Container Classes
Atomic Operations
Type Traits
Regular Expressions
New Smart Pointers
Multithreading Library
TR1에 추가된 내용들이 대부분.
Boost에 상당부분 구현되어있다.
오늘은 Core한 부분을 보겠습니다.
4. Lambda Expressions
[capture](parameters)->return-type {body}
함수 안에 함수를 내장 할 수 있다.
Functor 를 암시적으로 만들 수 있음
int main()
{
char s[]="Hello World!";
int Uppercase = 0; //modified by the lambda
for_each(s, s+sizeof(s), [&Uppercase] (char c) {
if (isupper(c))
Uppercase++;
});
cout<< Uppercase<<" uppercase letters in: "<< s<<endl;
}
5. Automatic Type Deduction and decltype
vector<int>::const_iterator ci = vi.begin();
컴파일러는 사실 다 알고 있다.
auto ci = vi.begin();
const vector<int> vi;
// 실제로 vi.begin()이 호출되지는 않는다.
typedef decltype (vi.begin()) CIT;
CIT another_const_iterator;
6. Uniform Initialization Syntax
초기화는 { }로 대동단결
C c {0,0}; //C++11 only. Equivalent to: C c(0,0);
int* a = new int[3] { 1, 2, 0 };
class X {
int a[4];
public:
X() : a{1,2,3,4} {} //C++11, member array initializer
};
vector<string> vs={ "first", "second", "third"};
map singers = { {"Lady Gaga", "+1 (212) 555-7890"},
{"Beyonce Knowles", "+1 (212) 555-0987"} };
class C {
int a=7; //C++11 only
public:
C();
};
7. Deleted and Defaulted Functions
class X {
X& operator=(const X&) = delete; // Disallow copying
X(const X&) = delete;
};
X a;
X b(a); // compilation error!
class Y {
Y& operator=(const Y&) = default; // default copy
semantics
Y(const Y&) = default;
}
기본적인 동작을 하는 대입 연산자와 복사 생성자는 코드
를 구현할 필요가 없이 컴파일러에서 알아서 만들어준다.
9. Delegating Constructors
생성자에서 다른 생성자를 부를 수 있다
C++98
class X {
int a;
validate(int x) {
if (0<x && x<=max) a=x; else throw bad_X(x);
}
public:
X(int x) { validate(x); }
X() { validate(42); }
X(string s) { int x = lexical_cast<int>(s); validate(x); }
};
C++11
class X {
int a;
public:
X(int x) { if (0<x && x<=max) a=x; else throw bad_X(x); }
X() :X{42} { }
X(string s) :X{lexical_cast<int>(s)} { }
};
10. Rvalue References
C++의 Reference(&)는 Lvalue reference다.
A = B;
A – Lvalue / B – Rvalue
Rvalue reference - &&으로 표기
임시 객체를 바인딩할 수 있다
A& a_ref3 = A(); // Error!
A&& a_ref4 = A(); // Ok
11. Move Semantics
C++03까지의 swap
template <class T> swap(T& a, T& b)
{
T tmp(a); // now we have two copies of a
a = b; // now we have two copies of b
b = tmp; // now we have two copies of tmp
(aka a)
}
vector 같은 container는 멤버함수로 swap을 구현한
다음에 swap에 대해서 템플릿 특화를 해야 했다
swap(vector<T>& left, vector<T>& right)
{ left.swap(right); }
직접 만드는 클래스도 비슷하게 구현할 수 있지만…
어떤 알고리즘에서 쓰일 줄 알고? 다 구현해야 하나?
12. C++11의 swap
template <class T> swap(T& a, T& b)
{
T tmp(std::move(a));
a = std::move(b);
b = std::move(tmp);
}
std::move 는 값을 반환하는데, 원본의 값이 유지될
필요가 없다
a의 값은 tmp로 넘어가고, b의 값은 a로 넘어가고, tmp의
값은 다시 b로 넘어간다. 복사가 아니다.
13. move를 지원하기 위해서는
class에 move contructor와 move assignment operator를 구현해야 한다.
class Derived
: public Base
{
std::vector<int> vec;
std::string name;
public:
// …
// move semantics
Derived(Derived&& x) // rvalues bind here
: Base(std::move(x)),
vec(std::move(x.vec)),
name(std::move(x.name))
{ }
Derived& operator=(Derived&& x) // rvalues bind here
{
Base::operator=(std::move(x));
vec = std::move(x.vec);
name = std::move(x.name);
return *this;
}
// …
};
14. 복사는 불가해도 이동은 가능한 타입이 가능
fstream
unique_ptr
auto_ptr이 사라지고 새로 들어감
non-shared, non-copiable ownership
기타 등등
17. static_assert
#include <iostream>
using namespace std;
int main()
{
static_assert( sizeof(int) == 4, "not int size 4" );
return 0;
}
assert와 비슷한 조건 조사를 할 수 있음
컴파일 타임 때 사용
템플릿 프로그래밍에 사용하면 유용하다