ݺߣ

ݺߣShare a Scribd company logo
C++ Korea 5th Seminar
C++20 Key Features Summary
???
Nexon Korea, Microsoft MVP
utilForever@gmail.com
??
??? (Chris Ohk)
? ?? ??? ?? ?????
? Microsoft Developer Technologies MVP
? ???? ?? C++ Korea ??
? IT ??? ?? ? ?? ??
? ?????? ?? ? ? ?? ?? ??? (2013)
? ??? Shader? Effect ?? (2014)
? 2D ?? ????? (2014)
? ??? ?? ?? (2017)
? ?? C++ ?? (2017)
? C++ ??? (2019)
?? ?? ?? ?? C++ Korea 5th Seminar
C++20 Key Features Summary
???? ??...
? C++20? ??? ?? ???? ?????.
? C++20? ??? ?? ? C++11/14/17 ??? ??? ??,
??? ?? ?? ?? ??? ?? ?????.
? ?? ?????? ??? ? ?? ?? ??? ?????.
(?? ?? ??? ??? ????? ???? ??)
? ?? ?? ??? ?? ?? Github? ?? ?????.
(https://github.com/utilForever/ModernCpp)
C++ Korea 5th Seminar
C++20 Key Features Summary
?? ?? C++ ?? ?? C++ Korea 5th Seminar
C++20 Key Features Summary
?? ?? C++ ?? ?? C++ Korea 5th Seminar
C++20 Key Features Summary
https://twitter.com/GorNishanov
?? ?? C++ ?? ?? C++ Korea 5th Seminar
C++20 Key Features Summary
https://twitter.com/GorNishanov
??? ?? C++ Korea 5th Seminar
C++20 Key Features Summary
https://twitter.com/walletfox
C++20 ?? ??
? Concepts
? Contracts
? Ranges
? Module
? Coroutines
C++ Korea 5th Seminar
C++20 Key Features Summary
Concepts
? ?? ??? ?? ????
C++ Korea 5th Seminar
C++20 Key Features Summary
#include <algorithm>
#include <list>
int main()
{
std::list<int> l = { 2, 1, 3 };
std::sort(l.begin(), l.end());
}
Concepts
? ?? ??? ?? ????
C++ Korea 5th Seminar
C++20 Key Features Summary
Concepts
? ? ??? ??????
? template <class RandomIt>
void sort(RandomIt first, RandomIt last);
? ??? RandomIt? ValueSwappable? RandomAccessIterator? ?? ??
? ???? ???. ??? int?? ???(Iterator)? ???? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
Concepts
? C#??? ?? ??? ?? ??? ???? ?????? ?????.
? Icloneable
? Icomparable
? Iconvertible
? Iformattable
? Nullable
? ...
? C++?? ???? ??? ??? ???? ?????.
Concept? ???? ???? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
Concepts
? Concept? ??? ??? ?? ??? ??? ? ? ????.
? ?? ?? ?? concept ???? ?????.
??? ?? ??? bool??? ??, ??? ?? ?? ??? bool??? ???.
? requires ???? ?? ?? ??? ?????.
?? ??? constexpr bool ?? concept bool??? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
template <class T>
concept bool EqualityComparable()
{
return requires(T a, T b) {
{a == b}->Boolean; // Boolean is the concept defining
{a != b}->Boolean; // a type usable in boolean context
};
}
Concepts
? ???? ??? ?? ???? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
void f(const EqualityComparable&);
// OK, std::string satisfies EqualityComparable
f("abc"s);
// Error: not EqualityComparable
f(std::use_facet<std::ctype<char>>(std::locale{}));
Concepts
? Concept? ???? ?? ?? ? ??? ?????? ? ? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
In instantiation of 'void std::__sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator
= std::_List_iterator<int>;
_Compare = __gnu_cxx::__ops::_Iter_less_iter]':
error: no match for 'operator-' (operand types are
'std::_List_iterator<int>' and 'std::_List_iterator<int>')
std::__lg(__last - __first) * 2,
error: cannot call function 'void std::sort(_RAIter, _RAIter)
[with _RAIter = std::_List_iterator<int>]'
note: concept 'RandomAccessIterator()' was not satisfied
Concepts
? Concept ???? ??? ????.
? Basic : DefaultConstructible, MoveConstructible,
CopyConstructible, MoveAssignable, CopyAssignable,
Destructible
? Library-wide : EqualityComparable, LessThanComparable,
Swappable, ValueSwappable, NullablePointer, Hash, Allocator,
FunctionObject, Callable, Predicate
? Iterator : InputIterator, OutputIterator, ForwardIterator,
BidirectionalIterator, RandomAccessIterator,
ContiguousIterator
C++ Korea 5th Seminar
C++20 Key Features Summary
Contract
? ??? ?? ??? ?????. (maybe bugs be with you)
C++ Korea 5th Seminar
C++20 Key Features Summary
Contract
? ??? ??? ? ?? ??? ?? ???? ??
assert? static_assert? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
void print_number(int* myInt)
{
assert(myInt != nullptr);
std::cout << *myInt << "n";
}
int main()
{
int a = 10;
int *b = nullptr, *c = nullptr;
b = &a;
print_number(b); print_number(c);
}
template<typename T>
class ArrayView
{
T& operator[](size_t i)[[expects:i < size()]];
ArrayView(const vector<T>& v)[[ensures:data() == v.data()]];
};
Contract
? Contract? ?? ?? ?? ??? ?? ??? ???
assert()?? ?? ??? ????? ??? ? ?? ?????.
? expects : ?? ??(Pre-condition)? ?? ???
? ensures : ?? ??(Post-condition)? ?? ???
C++ Korea 5th Seminar
C++20 Key Features Summary
struct A {
bool f() const; bool g() const;
virtual std::string bhar()[[expects:f() && g()]];
virtual int hash()[[ensures:g()]];
virtual void gash()[[expects:g()]];
virtual double fash(int i) const[[expects:i > 0]];
};
struct B : A {
std::string bhar() override[[expects:f()]]; // ERROR: weakening.
int hash() override[[ensures:f() && g()]]; // ERROR: strengthening.
void gash() override[[expects:g()]]; // OK: repeat from base.
double fash(int) override; // OK: inherited from base.
};
Contract
? ??? ? ??? ?? ?? ???? ??? ?????? ?
?? ???? ?? ??? ????? ???? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
Ranges
? Ranges? ??? ??? ??? ????????.
? Ranges? ??
? ??? (Convenience) : ???? ??
? ??? ?? (Lazy Evaluation) : ?? ?? ?? ??, ???? ?? ??
? ??? (Composability) : ???? ?? ??, ?? ??? ??
? Ranges? ?? ? ? ?? ?? ??? ?? ???, ?? ?????
???? Ranges for C++ Standard Library? ?????.
(/seao/c-korea-2nd-seminar-ranges-for-the-cpp-standard-library)
C++ Korea 5th Seminar
C++20 Key Features Summary
Ranges
? [0 ~ 10)? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::vector<int> v(10);
for (int i = 0; i < 10; ++i)
v[i] = i;
std::vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Ranges
? [0 ~ 10)? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
#include <numeric>
std::vector<int> v(10);
std::iota(v.begin(), v.end(), 0);
std::vector<int> v(10);
ranges::iota(v, 0);
Ranges
? [0 ~ 15)?? 5?? ??? ??? ? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
vector<int> v =
view::iota(0, 15) |
view::group_by(quotient) |
view::transform(sum);
for (auto e : v)
cout << e << " "; cout << endl;
auto quotient = [](int a, int b) {
return a / 5 == b / 5;
};
auto sum = [](auto rng) {
return ranges::accumulaate(rng, 0);
};
Ranges
? ??2
+ ??2
= ??2
? ???? ? ??? ? ??, ??, ?? 100? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
auto triples = view::ints(1) >>= [] (int z) { return
view::ints(1, z + 1) >>= [=](int x) { return
view::ints(x, z + 1) >>= [=](int y) { return
yield_if(x*x + y*y == z*z,
std::make_tuple(x, y, z));
}; }; };
auto triangles = triples | view::take(100);
Module
? C++??? #include? ?? ?? ??? ?????.
? ??? ?? ?? ?? ?? ?? ??? ????? ????.
(?? ?? ???? ?? ?? ??? ???? ???.)
? ?? ??? ??? ??? ??? ? ?? ??? ???? ????.
? C# : using System.Linq;
? Java : import java.util.Scanner;
? Python : from path import pi
? ?? C++?? Module? ???? ?? ? ? ?? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
Module
? ???? Module?? ???? ? ???? 3?????.
? module : ??? ??? ??? ?????.
?) module M1 : ??? ??? ??? M1??.
? import : ??? ??? ??? ?????.
?) import M1 : ??? ??? ??? M1??.
? export : ??? ??? ?????? ?????.
?) export int f(int, int)
??? ??? ??? f?? ?? ??? int, ?? ??? (int, int)?.
C++ Korea 5th Seminar
C++20 Key Features Summary
Module
? ? cpp ???? ??? ??? ?? cpp ???? ???? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
// m1.cpp
module M1;
export int f(int, int);
int g(int x) { return x * x; }
int f(int x, int y) { return g(x) + g(y); }
// m2.cpp
module M2;
export int g(int, int);
import std.core;
int f(int x, int y) { return x + y; }
int g(int x, int y)
{
return f(abs(x), abs(y));
}
// main.cpp
import M1;
import M2;
int main()
{
printf(%dn,
f(3, 4) + g(3, 4));
}
Coroutine
? C++ Coroutine ????: ???, ????, ??? ??? ????
Coroutine? ?? ??? ??? ?????.
(?? ??? ?? ?? ??? ??? ???? ?? ??????.)
C++ Korea 5th Seminar
C++20 Key Features Summary
C++20 ?? ??
? Designated initializers
? operator<=>
? Relation operator/comparison
? Nested inline namespaces
? consteval fuctions
? Feature test macros
C++ Korea 5th Seminar
C++20 Key Features Summary
C++20 ?? ??
? std::span
? std::endian
? std::bit_cast
? Calender and timezone library
C++ Korea 5th Seminar
C++20 Key Features Summary
Designated initializers
? ??? ?? ???? ??? ???.
? ??? ?? ??? ??? ???.
? ?? x, z?? ?? ???? ??? ??? ?? ????
??? ??? ?? ? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
struct A { int x; int y; int z; };
A a1{3, 4};
A a2{3, 4, 5};
A a1;
a1.x = 3;
a1.z = 5;
Designated initializers
? C++20??? ? ? ?? ???? ??? ? ????.
? ?, ??? ??? ??? ?? ??? ???? ???.
? ????? ??? ? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
A a1{.x = 3, .z = 5};
A a1{.x = 3, .y = 4}; // OK
A a2{.y = 4, .x = 3}; // Error
union u { int a; const char* b; };
u f = { .b = "asdf" }; // OK, active member of the union is b
u g = { .a = 1,.b = "asdf" }; // Error, only one initializer may be provided
operator<=>
? strcmp? ??? ??? ?? 3??? ?? ???? ??????.
(Spaceship operator, 3-way comparison???? ???.)
? a? b?? ?? 1? ?????.
? a? b?? ??? -1? ?????.
? a? b? ???(equal) ????(equivalent) 0? ?????.
(?? : ??? ????? ?? ?????.)
C++ Korea 5th Seminar
C++20 Key Features Summary
(a <=> b) < 0 // true if a < b
(a <=> b) < 0 // true if a > b
(a <=> b) == 0 // true if a is equal/equivalent to b
Relation operator/comparison
? ?? ? ????? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
??? 4m, ??? 1m? ???? ??? 1m, ??? 4m? ????
Relation operator/comparison
? ? ????? ??? ????. ??? ??? ????.
??? ? ???? ????? ??? ?? ??????
C++ Korea 5th Seminar
C++20 Key Features Summary
??? 4m, ??? 1m? ???? ??? 1m, ??? 4m? ????
Relation operator/comparison
? ? ? ? ????? ????? ???.
?? ?? weak ordering??? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
??? 4m, ??? 1m? ???? ??? 1m, ??? 4m? ????
Relation operator/comparison
? ?? ? ????? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
??? 4m, ??? 4m? ???? ??? 4m, ??? 4m? ????
Relation operator/comparison
? ? ????? ????.
??/?? ??? ?? ??? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
??? 4m, ??? 4m? ???? ??? 4m, ??? 4m? ????
Relation operator/comparison
? ?? ? ????? ???? ???.
?? ?? strong ordering??? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
??? 4m, ??? 4m? ???? ??? 4m, ??? 4m? ????
Relation operator/comparison
? operator<=>? ?? ??? ?? ?? ?? ? ??? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
https://medium.com/@barryrevzin/implementing-the-spaceship-operator-for-optional-4de89fc6d5ec
Relation operator/comparison
? ?? ??? ?? ???? ?? ??? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
https://medium.com/@barryrevzin/implementing-the-spaceship-operator-for-optional-4de89fc6d5ec
Relation operator/comparison
? operator<=> + relation operator? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
class Rectangle {
public:
Rectangle(int x, int y) : m_x(x), m_y(y) { }
int GetArea() const { return m_x * m_y; }
std::weak_ordering operator<=>(const Rectangle& r) const {
//if (auto cmp = m_x <=> r.m_x; cmp != 0) return cmp;
//if (auto cmp = m_y <=> r.m_y; cmp != 0) return cmp;
return GetArea() <=> r.GetArea();
}
private:
int m_x, m_y;
};
consteval functions
? constexpr ??
? ??? ??? ?? ???? ??? ??? ?????.
? ??? ??? ??? ????? ???? ?????.
? consteval ??
? ??? ??? ?? ???? ??? ??? ?????.
? ??? ??? ??? ????? ??? ??? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
consteval functions
? ??? ??? ??? ??? ??? ?? ???? ?????.
? consteval? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
consteval int sqr(int n) { return n * n; }
constexpr int r = sqr(100); // OK
consteval int sqrsqr(int n)
{
return sqr(sqr(n)); // OK
}
constexpr int dblsqr(int n)
{
return 2 * sqr(n); // Error
}
Nested inline namespaces
? ?? ?????? + ???
C++ Korea 5th Seminar
C++20 Key Features Summary
namespace A::B::inline C
{
...
}
namespace A::B
{
inline namespace C
{
...
}
}
=
Nested inline namespaces
? ?? ?????? + ???
C++ Korea 5th Seminar
C++20 Key Features Summary
namespace A::inline B::C
{
...
}
namespace A
{
inline namespace B
{
namespace C
{
...
}
}
}
=
Feature test macros
? ???? ??? C++ ????? ????.
? GCC
? Clang
? MSVC
? EDG eccp
? Intel C++
? Portland Group (PGI)
? ...
C++ Korea 5th Seminar
C++20 Key Features Summary
Feature test macros
? ?????? ??? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
Feature test macros
? ???? ?? ? ??? ?? ?? ?? ??? ????.
(apple-clang ?????... ??? ?? ????. brew install clang)
C++ Korea 5th Seminar
C++20 Key Features Summary
#if defined(ROSETTASTONE_WINDOWS)
#include <filesystem>
#elif defined(ROSETTASTONE_LINUX)
#include <experimental/filesystem>
#elif defined(ROSETTASTONE_MACOSX)
#include <sys/stat.h>
#endif
#if defined(ROSETTASTONE_WINDOWS)
namespace filesystem = std::filesystem;
#elif defined(ROSETTASTONE_LINUX)
namespace filesystem = std::experimental::filesystem;
#endif
Feature test macros
? ???? ?? ??? ???? ?? ??? ??? ??? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
#ifdef __has_include
# if __has_include(<optional>)
# include <optional>
# elif __has_include(<experimental/optional>)
# include <experimental/optional>
# elif __has_include(<boost/optional.hpp>)
# include <boost/optional.hpp>
# else
# error "Missing <optional>"
# endif
#endif
Feature test macros
? C++20?? ?? ??? ????? ??? ??????,
???? ??? C++? ?? ??? ???? ???? ? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
#if __cpp_constexpr >= 201304
# define CONSTEXPR constexpr
#else
# define CONSTEXPR inline
#endif
CONSTEXPR int bar(unsigned i)
{
...
}
Feature test macros
? C++20?? ?? ??? ????? ??? ??????,
???? ??? C++? ?? ??? ???? ???? ? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
CONSTEXPR int bar(unsigned i)
{
#if __cpp_binary_literals
unsigned mask1 = 0b11000000;
unsigned mask2 = 0b00000111;
#else
unsigned mask1 = 0xC0;
unsigned mask2 = 0x07;
#endif
if ( i & mask1 ) return 1;
if ( i & mask2 ) return 2;
return 0;
}
Feature test macros
? ??? C++20? ?? ??? __has_cpp_attribute? ????
??(attribute) ?? ??? ??? ? ????.
C++ Korea 5th Seminar
C++20 Key Features Summary
#ifdef __has_cpp_attribute
# if __has_cpp_attribute(deprecated)
# define DEPRECATED(msg) [[deprecated(msg)]]
# endif
#endif
#ifndef DEPRECATED
# define DEPRECATED(msg)
#endif
DEPRECATED("foo() has been deprecated") void foo();
std::span
? std::array_view? ??? ??????.
? std::string <-> std::string_view? ?? ?????.
? ?? ??? ?? ?? ????? ?? ?????.
? std::vector
? std::string
? T[]
? T* + size
C++ Korea 5th Seminar
C++20 Key Features Summary
std::span
? std::span? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
https://cor3ntin.github.io/posts/span/
std::vector<std::string> greeting = { "hello", "world" };
std::span<std::string> span(greeting);
for (auto&& s : span)
{
s[0] = std::toupper(s[0]);
}
for (const auto& word : greeting)
{
std::cout << word << ' ';
}
std::endian
? ????? ?? ???? ???? ???? ??? ?? ? ????.
?? ?? ?? 0x12345678? ???? ??? ?,
? ? ??? (Big Endian) : 12 34 56 78
? ?? ??? (Little Endian) : 78 56 34 12
C++ Korea 5th Seminar
C++20 Key Features Summary
std::endian
? C++?? ??? ??? ??? ??? ?? ???? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
//! Byte swap unsigned int
uint32_t swap_uint32(uint32_t val)
{
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF);
return (val << 16) | (val >> 16);
}
//! Byte swap int
int32_t swap_int32(int32_t val)
{
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF);
return (val << 16) | ((val >> 16) & 0xFFFF);
}
https://stackoverflow.com/questions/2182002/convert-big-endian-to-little-endian-in-c-without-using-provided-func
std::endian
? ??? ?????? ?? ???? ????? ??? ???.
C++ Korea 5th Seminar
C++20 Key Features Summary
https://stackoverflow.com/questions/2182002/convert-big-endian-to-little-endian-in-c-without-using-provided-func
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || 
defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || 
defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || 
defined(__MIBSEB__)
// It's a big-endian target architecture
#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || 
defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || 
defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || 
defined(__MIPSEL) || defined(__MIPSEL__)
// It's a little-endian target architecture
#else
#error "I don't know what architecture this is!"
#endif
std::endian
? std::endian? ???? ??????.
C++ Korea 5th Seminar
C++20 Key Features Summary
template <typename T, std::endian endianess = std::endian::native>
std::string HEX__1(const T & value, size_t value_size = sizeof(T)) {
using namespace std;
uint8_t* buffer = (uint8_t*)(&value);
char converted[value_size * 2 + 1];
if (endianess == std::endian::big)
for (size_t i = 0; i < value_size; ++i) {
sprintf(&converted[i * 2], "%02X", buffer[i]);
}
else
for (size_t i = 0; i < value_size; ++i) {
sprintf(&converted[i * 2], "%02X", buffer[value_size - 1 - i]);
}
return converted;
}
https://gist.github.com/ivanstepanovftw/9159efe123140c45d9df02e3d0454152
std::bit_cast
? ?? ?? ??? ??????.
C++ Korea 5th Seminar
C++20 Key Features Summary
https://en.cppreference.com/w/cpp/numeric/bit_cast
constexpr double f64v = 19880124.0;
constexpr auto u64v = std::bit_cast<std::uint64_t>(f64v);
constexpr std::uint64_t u64v2 = 0x3fe9000000000000ull;
constexpr auto f64v2 = std::bit_cast<double>(u64v2);
int main() {
std::cout
<< std::fixed << f64v << "f64.to_bits() == 0x"
<< std::hex << u64v << "u64n";
std::cout
<< "f64::from_bits(0x" << std::hex << u64v2 << "u64) == "
<< std::fixed << f64v2 << "f64n";
}
Calender and timezone library
? C++11 ??? <chrono> ?????? ???????.
??? ??? ??? ? ???? ?? ???? ?????.
? C++20? <chrono> ??????? ?? ??? ?????.
? ?? ?? ??? ??
? ??? ?? ??? ??
? ?? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
Calender and timezone library
? ?? ?? ???
? UTC(?? ???) ?? : utc_clock
? system_time <-> utc_time? ?? from_sys/to_sys ?? ??
? TAI(?? ???) ?? : tai_clock
? utc_time <-> tai_time? ?? from_utc/to_utc ?? ??
? GPS ?? : gps_clock
? utc_time <-> utc_time? ?? from_utc/to_utc ?? ??
? ?? ?? ?? : clock_cast
C++ Korea 5th Seminar
C++20 Key Features Summary
Calender and timezone library
? ?? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
using sys_days = std::chrono::time_point<
std::chrono::system_clock, std::chrono::days>;
sys_days st(1997_y / dec / 12);
auto ut = utc_clock::from_sys(st);
auto tt = tai_clock::from_utc(ut);
auto gt = gps_clock::from_utc(ut);
assert(clock_cast<sys_clock>(st) == st);
assert(clock_cast<utc_clock>(ut) == ut);
assert(clock_cast<tai_clock>(tt) == tt);
assert(clock_cast<gps_clock>(gt) == gt);
Calender and timezone library
? ??? ?? ???
? ?/?/? ?? : year_month_day
? ?? ? ??? ??? ? ???? (?/?/?, ?/?/?, ?/?/?)
? ??? ?? ?? ??
? year_month_day_last : ?? ?/?? ??? ?? ???? ???
? month_day_last : ?? ?? ??? ?? ???? ???
? weekday_last : ?? ?? ??? ??? ???? ???
? weekday_indexed : ?? ?? n?? ??? ???? ???
C++ Korea 5th Seminar
C++20 Key Features Summary
Calender and timezone library
? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
auto d1 = 2018_y / mar / 27;
auto d2 = 27_d / mar / 2018;
auto d3 = mar / 27 / 2018;
year_month_day today = floor<days>(system_clock::now());
assert(d1 == d2);
assert(d2 == d3);
assert(d3 == today);
https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
Calender and timezone library
? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
auto today = year_month_day{
floor<days>(system_clock::now()) };
auto ymdl = year_month_day_last(today.year(),
month_day_last{ month{ 2 } });
auto last_day_feb = year_month_day{ ymdl };
assert(last_day_feb == 2018_y / feb / 28); // for 2018
inline int number_of_days(sys_days const& first,
sys_days const& last)
{
return (last - first).count();
}
auto days = number_of_days(2018_y / apr / 1, 2018_y / dec / 25);
assert(days == 268);
Calender and timezone library
? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
Calender and timezone library
? ?? ??? ?? ???
? ?? ??
? locate_zone : ??? ??? ?? ???? ?? ??
? current_zone : ?? ?? ???? ?? ???? ?? ??
? ?? ??? ? ??
? sys_info, local_info
? zoned_traits, zoned_time
? choose, leap, link
? nonexistent_local_time
? ambiguous_local_time
C++ Korea 5th Seminar
C++20 Key Features Summary
auto time = floor<std::chrono::milliseconds>(system_clock::now());
std::cout << std::left << std::setw(25) << std::setfill(' ')
<< "Time"
<< time << std::endl;
auto localtime =
zoned_time<std::chrono::milliseconds>(date::current_zone(), time);
std::cout << std::left << std::setw(25) << std::setfill(' ')
<< "Local"
<< localtime << std::endl;
Calender and timezone library
? ?? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
auto zone_names = {
"Asia/Tokyo",
"Asia/Hong_Kong",
"Europe/Bucharest",
"Europe/Berlin",
"Europe/London",
"America/New_York",
"Pacific/Honolulu",
};
for(auto const& name : zone_names)
std::cout << std::left << std::setw(25) << std::setfill(' ')
<< name
<< zoned_time<std::chrono::milliseconds>(name, localtime)
<< std::endl;
Calender and timezone library
? ?? ??? ?? ??? ??
C++ Korea 5th Seminar
C++20 Key Features Summary
https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
??? ?? C++20? ? ??
? Synchronized output
? char8_t
? [[likely]], [[unlikely]] attribute
? [[no_unique_address]] attribute
? constexpr
? virtual functions
? dynamic_cast
? typeid
? try-catch
C++ Korea 5th Seminar
C++20 Key Features Summary
??? ?? C++20? ? ??
? std::remove_cvref
? std::atomic_ref
? std::atomic_shared_ptr
? std::atomic_weak_ptr
? std::destroying_delete
C++ Korea 5th Seminar
C++20 Key Features Summary
C++20? ??? ?? ?? ??
? Expansion statements
? constexpr std::vector
? std::format
? std::source_location
? std::flatmap, std::flatset
? std::byteswap
? using enum
C++ Korea 5th Seminar
C++20 Key Features Summary
??
? C++20 ??? ??? ??? ??? ?? ?? ????.
? C++20? ???? C++11 ?? ? ??? ??? ?????.
? ??? ?? ??? ??? ?? / ?? ???? ????.
? ? ??? ?????? ??? ? ??? ? ??? ????.
? ?? C++? ??? ??? ???????,
?? ???? ???? ??? ?? ??? ?????.
C++ Korea 5th Seminar
C++20 Key Features Summary
?????
http://github.com/utilForever
?? ?????!

More Related Content

What's hot (20)

Modern C++ ?????? ?? CPP11/14 ??
Modern C++ ?????? ?? CPP11/14 ??Modern C++ ?????? ?? CPP11/14 ??
Modern C++ ?????? ?? CPP11/14 ??
?? ?
?
NDC12_Lockless?????????
NDC12_Lockless?????????NDC12_Lockless?????????
NDC12_Lockless?????????
noerror
?
[NDC08] ???? ????? - ???
[NDC08] ???? ????? - ???[NDC08] ???? ????? - ???
[NDC08] ???? ????? - ???
ChangKyu Song
?
GPGPU(CUDA)? ??? MMOG ??? ????
GPGPU(CUDA)? ??? MMOG ??? ????GPGPU(CUDA)? ??? MMOG ??? ????
GPGPU(CUDA)? ??? MMOG ??? ????
YEONG-CHEON YOU
?
[NDC2016] TERA ??? Modern C++ ???
[NDC2016] TERA ??? Modern C++ ???[NDC2016] TERA ??? Modern C++ ???
[NDC2016] TERA ??? Modern C++ ???
Sang Heon Lee
?
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
Oliver N
?
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCP
Seungmo Koo
?
???, unity build? ???? ?????, NDC2010
???, unity build? ???? ?????, NDC2010???, unity build? ???? ?????, NDC2010
???, unity build? ???? ?????, NDC2010
devCAT Studio, NEXON
?
Multithread & shared_ptr
Multithread & shared_ptrMultithread & shared_ptr
Multithread & shared_ptr
?? ?
?
Clean code slide
Clean code slideClean code slide
Clean code slide
Anh Huan Miu
?
NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????
NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????
NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????
Jaeseung Ha
?
?? ??? ??? ?? ?? ??? NDC2011
?? ??? ??? ?? ?? ??? NDC2011?? ??? ??? ?? ?? ??? NDC2011
?? ??? ??? ?? ?? ??? NDC2011
Esun Kim
?
?? ??? ?? ??? (???, ???? Naver)
?? ??? ?? ??? (???, ???? Naver)?? ??? ?? ??? (???, ???? Naver)
?? ??? ?? ??? (???, ???? Naver)
Seungmo Koo
?
??? ?? ???? ??? ????? ???
??? ?? ???? ??? ????? ?????? ?? ???? ??? ????? ???
??? ?? ???? ??? ????? ???
Seungjae Lee
?
???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019
???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019
???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019
devCAT Studio, NEXON
?
ٱ𳾱ٱȲܳٴǤ
ٱ𳾱ٱȲܳٴǤٱ𳾱ٱȲܳٴǤ
ٱ𳾱ٱȲܳٴǤ
MITSUNARI Shigeo
?
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc
?
????? ????? ?? - ??? ? ????? ??? ??
????? ????? ?? - ??? ? ????? ??? ??????? ????? ?? - ??? ? ????? ??? ??
????? ????? ?? - ??? ? ????? ??? ??
Chris Ohk
?
?? 2: ????? ?????? ??? ?????
?? 2: ????? ?????? ??? ??????? 2: ????? ?????? ??? ?????
?? 2: ????? ?????? ??? ?????
?? ?
?
Modern C++ ?????? ?? CPP11/14 ??
Modern C++ ?????? ?? CPP11/14 ??Modern C++ ?????? ?? CPP11/14 ??
Modern C++ ?????? ?? CPP11/14 ??
?? ?
?
NDC12_Lockless?????????
NDC12_Lockless?????????NDC12_Lockless?????????
NDC12_Lockless?????????
noerror
?
[NDC08] ???? ????? - ???
[NDC08] ???? ????? - ???[NDC08] ???? ????? - ???
[NDC08] ???? ????? - ???
ChangKyu Song
?
GPGPU(CUDA)? ??? MMOG ??? ????
GPGPU(CUDA)? ??? MMOG ??? ????GPGPU(CUDA)? ??? MMOG ??? ????
GPGPU(CUDA)? ??? MMOG ??? ????
YEONG-CHEON YOU
?
[NDC2016] TERA ??? Modern C++ ???
[NDC2016] TERA ??? Modern C++ ???[NDC2016] TERA ??? Modern C++ ???
[NDC2016] TERA ??? Modern C++ ???
Sang Heon Lee
?
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
Oliver N
?
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCP
Seungmo Koo
?
???, unity build? ???? ?????, NDC2010
???, unity build? ???? ?????, NDC2010???, unity build? ???? ?????, NDC2010
???, unity build? ???? ?????, NDC2010
devCAT Studio, NEXON
?
Multithread & shared_ptr
Multithread & shared_ptrMultithread & shared_ptr
Multithread & shared_ptr
?? ?
?
NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????
NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????
NDC 2017 ??? NEXON ZERO (?? ??) ???? ????? ?? ?? ? ?? ?? ????
Jaeseung Ha
?
?? ??? ??? ?? ?? ??? NDC2011
?? ??? ??? ?? ?? ??? NDC2011?? ??? ??? ?? ?? ??? NDC2011
?? ??? ??? ?? ?? ??? NDC2011
Esun Kim
?
?? ??? ?? ??? (???, ???? Naver)
?? ??? ?? ??? (???, ???? Naver)?? ??? ?? ??? (???, ???? Naver)
?? ??? ?? ??? (???, ???? Naver)
Seungmo Koo
?
??? ?? ???? ??? ????? ???
??? ?? ???? ??? ????? ?????? ?? ???? ??? ????? ???
??? ?? ???? ??? ????? ???
Seungjae Lee
?
???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019
???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019
???, Enum? Boxing? ????? ???? ???? Enum ????, NDC2019
devCAT Studio, NEXON
?
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc
?
????? ????? ?? - ??? ? ????? ??? ??
????? ????? ?? - ??? ? ????? ??? ??????? ????? ?? - ??? ? ????? ??? ??
????? ????? ?? - ??? ? ????? ??? ??
Chris Ohk
?
?? 2: ????? ?????? ??? ?????
?? 2: ????? ?????? ??? ??????? 2: ????? ?????? ??? ?????
?? 2: ????? ?????? ??? ?????
?? ?
?

Similar to C++20 Key Features Summary (20)

???? ??? ??, From c++98 to c++11, 14
???? ??? ??, From c++98 to c++11, 14 ???? ??? ??, From c++98 to c++11, 14
???? ??? ??, From c++98 to c++11, 14
?? ?
?
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10
?? ?
?
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
Chris Ohk
?
Changes in c++0x
Changes in c++0xChanges in c++0x
Changes in c++0x
4002 JOF
?
?? ?????1? W.E.L.C.
?? ?????1?  W.E.L.C.?? ?????1?  W.E.L.C.
?? ?????1? W.E.L.C.
Ryan Park
?
Boost?????????? 20151111 ???
Boost?????????? 20151111 ???Boost?????????? 20151111 ???
Boost?????????? 20151111 ???
JinTaek Seo
?
[C++ Korea] Effective Modern C++ Study item 24-26
[C++ Korea] Effective Modern C++ Study item 24-26[C++ Korea] Effective Modern C++ Study item 24-26
[C++ Korea] Effective Modern C++ Study item 24-26
Seok-joon Yun
?
?? C++ ??
?? C++ ???? C++ ??
?? C++ ??
Hansol Kang
?
C++ 11 ? ??? ?? ????? 1?
C++ 11 ? ??? ?? ????? 1?C++ 11 ? ??? ?? ????? 1?
C++ 11 ? ??? ?? ????? 1?
Gwangwhi Mah
?
[C++ Korea] Effective Modern C++ Study item14 16 +??
[C++ Korea] Effective Modern C++ Study item14 16 +??[C++ Korea] Effective Modern C++ Study item14 16 +??
[C++ Korea] Effective Modern C++ Study item14 16 +??
Seok-joon Yun
?
C?? ??? - ??
C?? ??? - ??C?? ??? - ??
C?? ??? - ??
SeungHyun Lee
?
Ai C#???
Ai C#???Ai C#???
Ai C#???
Astin Choi
?
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
MinGeun Park
?
??????? ??? ?? C++
??????? ??? ?? C++??????? ??? ?? C++
??????? ??? ?? C++
KWANGIL KIM
?
[C++ korea] Effective Modern C++ ?? Study Item20,21,23
[C++ korea] Effective Modern C++ ?? Study Item20,21,23[C++ korea] Effective Modern C++ ?? Study Item20,21,23
[C++ korea] Effective Modern C++ ?? Study Item20,21,23
Seok-joon Yun
?
???? ???? ???? ???? - PyCon Korea 2018
???? ???? ???? ???? - PyCon Korea 2018???? ???? ???? ???? - PyCon Korea 2018
???? ???? ???? ???? - PyCon Korea 2018
Kenneth Ceyer
?
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
Seok-joon Yun
?
Angular2? ?? ??????
Angular2? ?? ??????Angular2? ?? ??????
Angular2? ?? ??????
Jin wook
?
08? ??? ??? (??)
08? ??? ??? (??)08? ??? ??? (??)
08? ??? ??? (??)
?? ?
?
???? ??? ??, From c++98 to c++11, 14
???? ??? ??, From c++98 to c++11, 14 ???? ??? ??, From c++98 to c++11, 14
???? ??? ??, From c++98 to c++11, 14
?? ?
?
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10
?? ?
?
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
Chris Ohk
?
Changes in c++0x
Changes in c++0xChanges in c++0x
Changes in c++0x
4002 JOF
?
?? ?????1? W.E.L.C.
?? ?????1?  W.E.L.C.?? ?????1?  W.E.L.C.
?? ?????1? W.E.L.C.
Ryan Park
?
Boost?????????? 20151111 ???
Boost?????????? 20151111 ???Boost?????????? 20151111 ???
Boost?????????? 20151111 ???
JinTaek Seo
?
[C++ Korea] Effective Modern C++ Study item 24-26
[C++ Korea] Effective Modern C++ Study item 24-26[C++ Korea] Effective Modern C++ Study item 24-26
[C++ Korea] Effective Modern C++ Study item 24-26
Seok-joon Yun
?
C++ 11 ? ??? ?? ????? 1?
C++ 11 ? ??? ?? ????? 1?C++ 11 ? ??? ?? ????? 1?
C++ 11 ? ??? ?? ????? 1?
Gwangwhi Mah
?
[C++ Korea] Effective Modern C++ Study item14 16 +??
[C++ Korea] Effective Modern C++ Study item14 16 +??[C++ Korea] Effective Modern C++ Study item14 16 +??
[C++ Korea] Effective Modern C++ Study item14 16 +??
Seok-joon Yun
?
[C++ korea] Effective Modern C++ ?? Study Item20,21,23
[C++ korea] Effective Modern C++ ?? Study Item20,21,23[C++ korea] Effective Modern C++ ?? Study Item20,21,23
[C++ korea] Effective Modern C++ ?? Study Item20,21,23
Seok-joon Yun
?
???? ???? ???? ???? - PyCon Korea 2018
???? ???? ???? ???? - PyCon Korea 2018???? ???? ???? ???? - PyCon Korea 2018
???? ???? ???? ???? - PyCon Korea 2018
Kenneth Ceyer
?
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
Seok-joon Yun
?
Angular2? ?? ??????
Angular2? ?? ??????Angular2? ?? ??????
Angular2? ?? ??????
Jin wook
?
08? ??? ??? (??)
08? ??? ??? (??)08? ??? ??? (??)
08? ??? ??? (??)
?? ?
?

More from Chris Ohk (20)

??? 2022 - Rust ??? ??? ?????
??? 2022 - Rust ??? ??? ???????? 2022 - Rust ??? ??? ?????
??? 2022 - Rust ??? ??? ?????
Chris Ohk
?
Momenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStoneMomenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStone
Chris Ohk
?
????????? 2021 ???? ???? - Rust? ???? ?? ????
????????? 2021 ???? ???? - Rust? ???? ?? ????????????? 2021 ???? ???? - Rust? ???? ?? ????
????????? 2021 ???? ???? - Rust? ???? ?? ????
Chris Ohk
?
Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2
Chris Ohk
?
Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1
Chris Ohk
?
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Chris Ohk
?
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Chris Ohk
?
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Chris Ohk
?
Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017
Chris Ohk
?
Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015
Chris Ohk
?
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Chris Ohk
?
GDG Gwangju DevFest 2019 - <????> ???? ?? ???
GDG Gwangju DevFest 2019 - <????> ???? ?? ???GDG Gwangju DevFest 2019 - <????> ???? ?? ???
GDG Gwangju DevFest 2019 - <????> ???? ?? ???
Chris Ohk
?
[RLKorea] <????> ???? ?? ???
[RLKorea] <????> ???? ?? ???[RLKorea] <????> ???? ?? ???
[RLKorea] <????> ???? ?? ???
Chris Ohk
?
[NDC 2019] ???? ???? ?? ???
[NDC 2019] ???? ???? ?? ???[NDC 2019] ???? ???? ?? ???
[NDC 2019] ???? ???? ?? ???
Chris Ohk
?
[????] ??? ?? - ???? ?? ???????
[????] ??? ?? - ???? ?? ???????[????] ??? ?? - ???? ?? ???????
[????] ??? ?? - ???? ?? ???????
Chris Ohk
?
??? ?? - ??? ????? ?????
??? ?? - ??? ????? ???????? ?? - ??? ????? ?????
??? ?? - ??? ????? ?????
Chris Ohk
?
??? ?? - ???? ??? ???
??? ?? - ???? ??? ?????? ?? - ???? ??? ???
??? ?? - ???? ??? ???
Chris Ohk
?
[NDC 2018] ???? ?? ???
[NDC 2018] ???? ?? ???[NDC 2018] ???? ?? ???
[NDC 2018] ???? ?? ???
Chris Ohk
?
My Way, Your Way
My Way, Your WayMy Way, Your Way
My Way, Your Way
Chris Ohk
?
Re:Zero?? ???? ?? ???? ??
Re:Zero?? ???? ?? ???? ??Re:Zero?? ???? ?? ???? ??
Re:Zero?? ???? ?? ???? ??
Chris Ohk
?
??? 2022 - Rust ??? ??? ?????
??? 2022 - Rust ??? ??? ???????? 2022 - Rust ??? ??? ?????
??? 2022 - Rust ??? ??? ?????
Chris Ohk
?
Momenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStoneMomenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStone
Chris Ohk
?
????????? 2021 ???? ???? - Rust? ???? ?? ????
????????? 2021 ???? ???? - Rust? ???? ?? ????????????? 2021 ???? ???? - Rust? ???? ?? ????
????????? 2021 ???? ???? - Rust? ???? ?? ????
Chris Ohk
?
Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2
Chris Ohk
?
Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1
Chris Ohk
?
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Chris Ohk
?
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Chris Ohk
?
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Chris Ohk
?
Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017
Chris Ohk
?
Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015
Chris Ohk
?
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Chris Ohk
?
GDG Gwangju DevFest 2019 - <????> ???? ?? ???
GDG Gwangju DevFest 2019 - <????> ???? ?? ???GDG Gwangju DevFest 2019 - <????> ???? ?? ???
GDG Gwangju DevFest 2019 - <????> ???? ?? ???
Chris Ohk
?
[RLKorea] <????> ???? ?? ???
[RLKorea] <????> ???? ?? ???[RLKorea] <????> ???? ?? ???
[RLKorea] <????> ???? ?? ???
Chris Ohk
?
[NDC 2019] ???? ???? ?? ???
[NDC 2019] ???? ???? ?? ???[NDC 2019] ???? ???? ?? ???
[NDC 2019] ???? ???? ?? ???
Chris Ohk
?
[????] ??? ?? - ???? ?? ???????
[????] ??? ?? - ???? ?? ???????[????] ??? ?? - ???? ?? ???????
[????] ??? ?? - ???? ?? ???????
Chris Ohk
?
??? ?? - ??? ????? ?????
??? ?? - ??? ????? ???????? ?? - ??? ????? ?????
??? ?? - ??? ????? ?????
Chris Ohk
?
??? ?? - ???? ??? ???
??? ?? - ???? ??? ?????? ?? - ???? ??? ???
??? ?? - ???? ??? ???
Chris Ohk
?
[NDC 2018] ???? ?? ???
[NDC 2018] ???? ?? ???[NDC 2018] ???? ?? ???
[NDC 2018] ???? ?? ???
Chris Ohk
?
My Way, Your Way
My Way, Your WayMy Way, Your Way
My Way, Your Way
Chris Ohk
?
Re:Zero?? ???? ?? ???? ??
Re:Zero?? ???? ?? ???? ??Re:Zero?? ???? ?? ???? ??
Re:Zero?? ???? ?? ???? ??
Chris Ohk
?

C++20 Key Features Summary

  • 1. C++ Korea 5th Seminar C++20 Key Features Summary ??? Nexon Korea, Microsoft MVP utilForever@gmail.com
  • 2. ?? ??? (Chris Ohk) ? ?? ??? ?? ????? ? Microsoft Developer Technologies MVP ? ???? ?? C++ Korea ?? ? IT ??? ?? ? ?? ?? ? ?????? ?? ? ? ?? ?? ??? (2013) ? ??? Shader? Effect ?? (2014) ? 2D ?? ????? (2014) ? ??? ?? ?? (2017) ? ?? C++ ?? (2017) ? C++ ??? (2019)
  • 3. ?? ?? ?? ?? C++ Korea 5th Seminar C++20 Key Features Summary
  • 4. ???? ??... ? C++20? ??? ?? ???? ?????. ? C++20? ??? ?? ? C++11/14/17 ??? ??? ??, ??? ?? ?? ?? ??? ?? ?????. ? ?? ?????? ??? ? ?? ?? ??? ?????. (?? ?? ??? ??? ????? ???? ??) ? ?? ?? ??? ?? ?? Github? ?? ?????. (https://github.com/utilForever/ModernCpp) C++ Korea 5th Seminar C++20 Key Features Summary
  • 5. ?? ?? C++ ?? ?? C++ Korea 5th Seminar C++20 Key Features Summary
  • 6. ?? ?? C++ ?? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://twitter.com/GorNishanov
  • 7. ?? ?? C++ ?? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://twitter.com/GorNishanov
  • 8. ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://twitter.com/walletfox
  • 9. C++20 ?? ?? ? Concepts ? Contracts ? Ranges ? Module ? Coroutines C++ Korea 5th Seminar C++20 Key Features Summary
  • 10. Concepts ? ?? ??? ?? ???? C++ Korea 5th Seminar C++20 Key Features Summary #include <algorithm> #include <list> int main() { std::list<int> l = { 2, 1, 3 }; std::sort(l.begin(), l.end()); }
  • 11. Concepts ? ?? ??? ?? ???? C++ Korea 5th Seminar C++20 Key Features Summary
  • 12. Concepts ? ? ??? ?????? ? template <class RandomIt> void sort(RandomIt first, RandomIt last); ? ??? RandomIt? ValueSwappable? RandomAccessIterator? ?? ?? ? ???? ???. ??? int?? ???(Iterator)? ???? ????. C++ Korea 5th Seminar C++20 Key Features Summary
  • 13. Concepts ? C#??? ?? ??? ?? ??? ???? ?????? ?????. ? Icloneable ? Icomparable ? Iconvertible ? Iformattable ? Nullable ? ... ? C++?? ???? ??? ??? ???? ?????. Concept? ???? ???? ???. C++ Korea 5th Seminar C++20 Key Features Summary
  • 14. Concepts ? Concept? ??? ??? ?? ??? ??? ? ? ????. ? ?? ?? ?? concept ???? ?????. ??? ?? ??? bool??? ??, ??? ?? ?? ??? bool??? ???. ? requires ???? ?? ?? ??? ?????. ?? ??? constexpr bool ?? concept bool??? ???. C++ Korea 5th Seminar C++20 Key Features Summary template <class T> concept bool EqualityComparable() { return requires(T a, T b) { {a == b}->Boolean; // Boolean is the concept defining {a != b}->Boolean; // a type usable in boolean context }; }
  • 15. Concepts ? ???? ??? ?? ???? ????. C++ Korea 5th Seminar C++20 Key Features Summary void f(const EqualityComparable&); // OK, std::string satisfies EqualityComparable f("abc"s); // Error: not EqualityComparable f(std::use_facet<std::ctype<char>>(std::locale{}));
  • 16. Concepts ? Concept? ???? ?? ?? ? ??? ?????? ? ? ????. C++ Korea 5th Seminar C++20 Key Features Summary In instantiation of 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]': error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::_List_iterator<int>') std::__lg(__last - __first) * 2, error: cannot call function 'void std::sort(_RAIter, _RAIter) [with _RAIter = std::_List_iterator<int>]' note: concept 'RandomAccessIterator()' was not satisfied
  • 17. Concepts ? Concept ???? ??? ????. ? Basic : DefaultConstructible, MoveConstructible, CopyConstructible, MoveAssignable, CopyAssignable, Destructible ? Library-wide : EqualityComparable, LessThanComparable, Swappable, ValueSwappable, NullablePointer, Hash, Allocator, FunctionObject, Callable, Predicate ? Iterator : InputIterator, OutputIterator, ForwardIterator, BidirectionalIterator, RandomAccessIterator, ContiguousIterator C++ Korea 5th Seminar C++20 Key Features Summary
  • 18. Contract ? ??? ?? ??? ?????. (maybe bugs be with you) C++ Korea 5th Seminar C++20 Key Features Summary
  • 19. Contract ? ??? ??? ? ?? ??? ?? ???? ?? assert? static_assert? ?????. C++ Korea 5th Seminar C++20 Key Features Summary void print_number(int* myInt) { assert(myInt != nullptr); std::cout << *myInt << "n"; } int main() { int a = 10; int *b = nullptr, *c = nullptr; b = &a; print_number(b); print_number(c); }
  • 20. template<typename T> class ArrayView { T& operator[](size_t i)[[expects:i < size()]]; ArrayView(const vector<T>& v)[[ensures:data() == v.data()]]; }; Contract ? Contract? ?? ?? ?? ??? ?? ??? ??? assert()?? ?? ??? ????? ??? ? ?? ?????. ? expects : ?? ??(Pre-condition)? ?? ??? ? ensures : ?? ??(Post-condition)? ?? ??? C++ Korea 5th Seminar C++20 Key Features Summary
  • 21. struct A { bool f() const; bool g() const; virtual std::string bhar()[[expects:f() && g()]]; virtual int hash()[[ensures:g()]]; virtual void gash()[[expects:g()]]; virtual double fash(int i) const[[expects:i > 0]]; }; struct B : A { std::string bhar() override[[expects:f()]]; // ERROR: weakening. int hash() override[[ensures:f() && g()]]; // ERROR: strengthening. void gash() override[[expects:g()]]; // OK: repeat from base. double fash(int) override; // OK: inherited from base. }; Contract ? ??? ? ??? ?? ?? ???? ??? ?????? ? ?? ???? ?? ??? ????? ???? ????. C++ Korea 5th Seminar C++20 Key Features Summary
  • 22. Ranges ? Ranges? ??? ??? ??? ????????. ? Ranges? ?? ? ??? (Convenience) : ???? ?? ? ??? ?? (Lazy Evaluation) : ?? ?? ?? ??, ???? ?? ?? ? ??? (Composability) : ???? ?? ??, ?? ??? ?? ? Ranges? ?? ? ? ?? ?? ??? ?? ???, ?? ????? ???? Ranges for C++ Standard Library? ?????. (/seao/c-korea-2nd-seminar-ranges-for-the-cpp-standard-library) C++ Korea 5th Seminar C++20 Key Features Summary
  • 23. Ranges ? [0 ~ 10)? ?????. C++ Korea 5th Seminar C++20 Key Features Summary int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector<int> v(10); for (int i = 0; i < 10; ++i) v[i] = i; std::vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  • 24. Ranges ? [0 ~ 10)? ?????. C++ Korea 5th Seminar C++20 Key Features Summary #include <numeric> std::vector<int> v(10); std::iota(v.begin(), v.end(), 0); std::vector<int> v(10); ranges::iota(v, 0);
  • 25. Ranges ? [0 ~ 15)?? 5?? ??? ??? ? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary vector<int> v = view::iota(0, 15) | view::group_by(quotient) | view::transform(sum); for (auto e : v) cout << e << " "; cout << endl; auto quotient = [](int a, int b) { return a / 5 == b / 5; }; auto sum = [](auto rng) { return ranges::accumulaate(rng, 0); };
  • 26. Ranges ? ??2 + ??2 = ??2 ? ???? ? ??? ? ??, ??, ?? 100? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary auto triples = view::ints(1) >>= [] (int z) { return view::ints(1, z + 1) >>= [=](int x) { return view::ints(x, z + 1) >>= [=](int y) { return yield_if(x*x + y*y == z*z, std::make_tuple(x, y, z)); }; }; }; auto triangles = triples | view::take(100);
  • 27. Module ? C++??? #include? ?? ?? ??? ?????. ? ??? ?? ?? ?? ?? ?? ??? ????? ????. (?? ?? ???? ?? ?? ??? ???? ???.) ? ?? ??? ??? ??? ??? ? ?? ??? ???? ????. ? C# : using System.Linq; ? Java : import java.util.Scanner; ? Python : from path import pi ? ?? C++?? Module? ???? ?? ? ? ?? ?????. C++ Korea 5th Seminar C++20 Key Features Summary
  • 28. Module ? ???? Module?? ???? ? ???? 3?????. ? module : ??? ??? ??? ?????. ?) module M1 : ??? ??? ??? M1??. ? import : ??? ??? ??? ?????. ?) import M1 : ??? ??? ??? M1??. ? export : ??? ??? ?????? ?????. ?) export int f(int, int) ??? ??? ??? f?? ?? ??? int, ?? ??? (int, int)?. C++ Korea 5th Seminar C++20 Key Features Summary
  • 29. Module ? ? cpp ???? ??? ??? ?? cpp ???? ???? ?? C++ Korea 5th Seminar C++20 Key Features Summary // m1.cpp module M1; export int f(int, int); int g(int x) { return x * x; } int f(int x, int y) { return g(x) + g(y); } // m2.cpp module M2; export int g(int, int); import std.core; int f(int x, int y) { return x + y; } int g(int x, int y) { return f(abs(x), abs(y)); } // main.cpp import M1; import M2; int main() { printf(%dn, f(3, 4) + g(3, 4)); }
  • 30. Coroutine ? C++ Coroutine ????: ???, ????, ??? ??? ???? Coroutine? ?? ??? ??? ?????. (?? ??? ?? ?? ??? ??? ???? ?? ??????.) C++ Korea 5th Seminar C++20 Key Features Summary
  • 31. C++20 ?? ?? ? Designated initializers ? operator<=> ? Relation operator/comparison ? Nested inline namespaces ? consteval fuctions ? Feature test macros C++ Korea 5th Seminar C++20 Key Features Summary
  • 32. C++20 ?? ?? ? std::span ? std::endian ? std::bit_cast ? Calender and timezone library C++ Korea 5th Seminar C++20 Key Features Summary
  • 33. Designated initializers ? ??? ?? ???? ??? ???. ? ??? ?? ??? ??? ???. ? ?? x, z?? ?? ???? ??? ??? ?? ???? ??? ??? ?? ? ????. C++ Korea 5th Seminar C++20 Key Features Summary struct A { int x; int y; int z; }; A a1{3, 4}; A a2{3, 4, 5}; A a1; a1.x = 3; a1.z = 5;
  • 34. Designated initializers ? C++20??? ? ? ?? ???? ??? ? ????. ? ?, ??? ??? ??? ?? ??? ???? ???. ? ????? ??? ? ????. C++ Korea 5th Seminar C++20 Key Features Summary A a1{.x = 3, .z = 5}; A a1{.x = 3, .y = 4}; // OK A a2{.y = 4, .x = 3}; // Error union u { int a; const char* b; }; u f = { .b = "asdf" }; // OK, active member of the union is b u g = { .a = 1,.b = "asdf" }; // Error, only one initializer may be provided
  • 35. operator<=> ? strcmp? ??? ??? ?? 3??? ?? ???? ??????. (Spaceship operator, 3-way comparison???? ???.) ? a? b?? ?? 1? ?????. ? a? b?? ??? -1? ?????. ? a? b? ???(equal) ????(equivalent) 0? ?????. (?? : ??? ????? ?? ?????.) C++ Korea 5th Seminar C++20 Key Features Summary (a <=> b) < 0 // true if a < b (a <=> b) < 0 // true if a > b (a <=> b) == 0 // true if a is equal/equivalent to b
  • 36. Relation operator/comparison ? ?? ? ????? ????. C++ Korea 5th Seminar C++20 Key Features Summary ??? 4m, ??? 1m? ???? ??? 1m, ??? 4m? ????
  • 37. Relation operator/comparison ? ? ????? ??? ????. ??? ??? ????. ??? ? ???? ????? ??? ?? ?????? C++ Korea 5th Seminar C++20 Key Features Summary ??? 4m, ??? 1m? ???? ??? 1m, ??? 4m? ????
  • 38. Relation operator/comparison ? ? ? ? ????? ????? ???. ?? ?? weak ordering??? ???. C++ Korea 5th Seminar C++20 Key Features Summary ??? 4m, ??? 1m? ???? ??? 1m, ??? 4m? ????
  • 39. Relation operator/comparison ? ?? ? ????? ????. C++ Korea 5th Seminar C++20 Key Features Summary ??? 4m, ??? 4m? ???? ??? 4m, ??? 4m? ????
  • 40. Relation operator/comparison ? ? ????? ????. ??/?? ??? ?? ??? ????. C++ Korea 5th Seminar C++20 Key Features Summary ??? 4m, ??? 4m? ???? ??? 4m, ??? 4m? ????
  • 41. Relation operator/comparison ? ?? ? ????? ???? ???. ?? ?? strong ordering??? ???. C++ Korea 5th Seminar C++20 Key Features Summary ??? 4m, ??? 4m? ???? ??? 4m, ??? 4m? ????
  • 42. Relation operator/comparison ? operator<=>? ?? ??? ?? ?? ?? ? ??? ???. C++ Korea 5th Seminar C++20 Key Features Summary https://medium.com/@barryrevzin/implementing-the-spaceship-operator-for-optional-4de89fc6d5ec
  • 43. Relation operator/comparison ? ?? ??? ?? ???? ?? ??? ????. C++ Korea 5th Seminar C++20 Key Features Summary https://medium.com/@barryrevzin/implementing-the-spaceship-operator-for-optional-4de89fc6d5ec
  • 44. Relation operator/comparison ? operator<=> + relation operator? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary class Rectangle { public: Rectangle(int x, int y) : m_x(x), m_y(y) { } int GetArea() const { return m_x * m_y; } std::weak_ordering operator<=>(const Rectangle& r) const { //if (auto cmp = m_x <=> r.m_x; cmp != 0) return cmp; //if (auto cmp = m_y <=> r.m_y; cmp != 0) return cmp; return GetArea() <=> r.GetArea(); } private: int m_x, m_y; };
  • 45. consteval functions ? constexpr ?? ? ??? ??? ?? ???? ??? ??? ?????. ? ??? ??? ??? ????? ???? ?????. ? consteval ?? ? ??? ??? ?? ???? ??? ??? ?????. ? ??? ??? ??? ????? ??? ??? ?????. C++ Korea 5th Seminar C++20 Key Features Summary
  • 46. consteval functions ? ??? ??? ??? ??? ??? ?? ???? ?????. ? consteval? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary consteval int sqr(int n) { return n * n; } constexpr int r = sqr(100); // OK consteval int sqrsqr(int n) { return sqr(sqr(n)); // OK } constexpr int dblsqr(int n) { return 2 * sqr(n); // Error }
  • 47. Nested inline namespaces ? ?? ?????? + ??? C++ Korea 5th Seminar C++20 Key Features Summary namespace A::B::inline C { ... } namespace A::B { inline namespace C { ... } } =
  • 48. Nested inline namespaces ? ?? ?????? + ??? C++ Korea 5th Seminar C++20 Key Features Summary namespace A::inline B::C { ... } namespace A { inline namespace B { namespace C { ... } } } =
  • 49. Feature test macros ? ???? ??? C++ ????? ????. ? GCC ? Clang ? MSVC ? EDG eccp ? Intel C++ ? Portland Group (PGI) ? ... C++ Korea 5th Seminar C++20 Key Features Summary
  • 50. Feature test macros ? ?????? ??? ?????. C++ Korea 5th Seminar C++20 Key Features Summary
  • 51. Feature test macros ? ???? ?? ? ??? ?? ?? ?? ??? ????. (apple-clang ?????... ??? ?? ????. brew install clang) C++ Korea 5th Seminar C++20 Key Features Summary #if defined(ROSETTASTONE_WINDOWS) #include <filesystem> #elif defined(ROSETTASTONE_LINUX) #include <experimental/filesystem> #elif defined(ROSETTASTONE_MACOSX) #include <sys/stat.h> #endif #if defined(ROSETTASTONE_WINDOWS) namespace filesystem = std::filesystem; #elif defined(ROSETTASTONE_LINUX) namespace filesystem = std::experimental::filesystem; #endif
  • 52. Feature test macros ? ???? ?? ??? ???? ?? ??? ??? ??? ???. C++ Korea 5th Seminar C++20 Key Features Summary #ifdef __has_include # if __has_include(<optional>) # include <optional> # elif __has_include(<experimental/optional>) # include <experimental/optional> # elif __has_include(<boost/optional.hpp>) # include <boost/optional.hpp> # else # error "Missing <optional>" # endif #endif
  • 53. Feature test macros ? C++20?? ?? ??? ????? ??? ??????, ???? ??? C++? ?? ??? ???? ???? ? ????. C++ Korea 5th Seminar C++20 Key Features Summary #if __cpp_constexpr >= 201304 # define CONSTEXPR constexpr #else # define CONSTEXPR inline #endif CONSTEXPR int bar(unsigned i) { ... }
  • 54. Feature test macros ? C++20?? ?? ??? ????? ??? ??????, ???? ??? C++? ?? ??? ???? ???? ? ????. C++ Korea 5th Seminar C++20 Key Features Summary CONSTEXPR int bar(unsigned i) { #if __cpp_binary_literals unsigned mask1 = 0b11000000; unsigned mask2 = 0b00000111; #else unsigned mask1 = 0xC0; unsigned mask2 = 0x07; #endif if ( i & mask1 ) return 1; if ( i & mask2 ) return 2; return 0; }
  • 55. Feature test macros ? ??? C++20? ?? ??? __has_cpp_attribute? ???? ??(attribute) ?? ??? ??? ? ????. C++ Korea 5th Seminar C++20 Key Features Summary #ifdef __has_cpp_attribute # if __has_cpp_attribute(deprecated) # define DEPRECATED(msg) [[deprecated(msg)]] # endif #endif #ifndef DEPRECATED # define DEPRECATED(msg) #endif DEPRECATED("foo() has been deprecated") void foo();
  • 56. std::span ? std::array_view? ??? ??????. ? std::string <-> std::string_view? ?? ?????. ? ?? ??? ?? ?? ????? ?? ?????. ? std::vector ? std::string ? T[] ? T* + size C++ Korea 5th Seminar C++20 Key Features Summary
  • 57. std::span ? std::span? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://cor3ntin.github.io/posts/span/ std::vector<std::string> greeting = { "hello", "world" }; std::span<std::string> span(greeting); for (auto&& s : span) { s[0] = std::toupper(s[0]); } for (const auto& word : greeting) { std::cout << word << ' '; }
  • 58. std::endian ? ????? ?? ???? ???? ???? ??? ?? ? ????. ?? ?? ?? 0x12345678? ???? ??? ?, ? ? ??? (Big Endian) : 12 34 56 78 ? ?? ??? (Little Endian) : 78 56 34 12 C++ Korea 5th Seminar C++20 Key Features Summary
  • 59. std::endian ? C++?? ??? ??? ??? ??? ?? ???? ???. C++ Korea 5th Seminar C++20 Key Features Summary //! Byte swap unsigned int uint32_t swap_uint32(uint32_t val) { val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); return (val << 16) | (val >> 16); } //! Byte swap int int32_t swap_int32(int32_t val) { val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); return (val << 16) | ((val >> 16) & 0xFFFF); } https://stackoverflow.com/questions/2182002/convert-big-endian-to-little-endian-in-c-without-using-provided-func
  • 60. std::endian ? ??? ?????? ?? ???? ????? ??? ???. C++ Korea 5th Seminar C++20 Key Features Summary https://stackoverflow.com/questions/2182002/convert-big-endian-to-little-endian-in-c-without-using-provided-func #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) // It's a big-endian target architecture #elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) // It's a little-endian target architecture #else #error "I don't know what architecture this is!" #endif
  • 61. std::endian ? std::endian? ???? ??????. C++ Korea 5th Seminar C++20 Key Features Summary template <typename T, std::endian endianess = std::endian::native> std::string HEX__1(const T & value, size_t value_size = sizeof(T)) { using namespace std; uint8_t* buffer = (uint8_t*)(&value); char converted[value_size * 2 + 1]; if (endianess == std::endian::big) for (size_t i = 0; i < value_size; ++i) { sprintf(&converted[i * 2], "%02X", buffer[i]); } else for (size_t i = 0; i < value_size; ++i) { sprintf(&converted[i * 2], "%02X", buffer[value_size - 1 - i]); } return converted; } https://gist.github.com/ivanstepanovftw/9159efe123140c45d9df02e3d0454152
  • 62. std::bit_cast ? ?? ?? ??? ??????. C++ Korea 5th Seminar C++20 Key Features Summary https://en.cppreference.com/w/cpp/numeric/bit_cast constexpr double f64v = 19880124.0; constexpr auto u64v = std::bit_cast<std::uint64_t>(f64v); constexpr std::uint64_t u64v2 = 0x3fe9000000000000ull; constexpr auto f64v2 = std::bit_cast<double>(u64v2); int main() { std::cout << std::fixed << f64v << "f64.to_bits() == 0x" << std::hex << u64v << "u64n"; std::cout << "f64::from_bits(0x" << std::hex << u64v2 << "u64) == " << std::fixed << f64v2 << "f64n"; }
  • 63. Calender and timezone library ? C++11 ??? <chrono> ?????? ???????. ??? ??? ??? ? ???? ?? ???? ?????. ? C++20? <chrono> ??????? ?? ??? ?????. ? ?? ?? ??? ?? ? ??? ?? ??? ?? ? ?? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary
  • 64. Calender and timezone library ? ?? ?? ??? ? UTC(?? ???) ?? : utc_clock ? system_time <-> utc_time? ?? from_sys/to_sys ?? ?? ? TAI(?? ???) ?? : tai_clock ? utc_time <-> tai_time? ?? from_utc/to_utc ?? ?? ? GPS ?? : gps_clock ? utc_time <-> utc_time? ?? from_utc/to_utc ?? ?? ? ?? ?? ?? : clock_cast C++ Korea 5th Seminar C++20 Key Features Summary
  • 65. Calender and timezone library ? ?? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary using sys_days = std::chrono::time_point< std::chrono::system_clock, std::chrono::days>; sys_days st(1997_y / dec / 12); auto ut = utc_clock::from_sys(st); auto tt = tai_clock::from_utc(ut); auto gt = gps_clock::from_utc(ut); assert(clock_cast<sys_clock>(st) == st); assert(clock_cast<utc_clock>(ut) == ut); assert(clock_cast<tai_clock>(tt) == tt); assert(clock_cast<gps_clock>(gt) == gt);
  • 66. Calender and timezone library ? ??? ?? ??? ? ?/?/? ?? : year_month_day ? ?? ? ??? ??? ? ???? (?/?/?, ?/?/?, ?/?/?) ? ??? ?? ?? ?? ? year_month_day_last : ?? ?/?? ??? ?? ???? ??? ? month_day_last : ?? ?? ??? ?? ???? ??? ? weekday_last : ?? ?? ??? ??? ???? ??? ? weekday_indexed : ?? ?? n?? ??? ???? ??? C++ Korea 5th Seminar C++20 Key Features Summary
  • 67. Calender and timezone library ? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary auto d1 = 2018_y / mar / 27; auto d2 = 27_d / mar / 2018; auto d3 = mar / 27 / 2018; year_month_day today = floor<days>(system_clock::now()); assert(d1 == d2); assert(d2 == d3); assert(d3 == today); https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
  • 68. Calender and timezone library ? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/ auto today = year_month_day{ floor<days>(system_clock::now()) }; auto ymdl = year_month_day_last(today.year(), month_day_last{ month{ 2 } }); auto last_day_feb = year_month_day{ ymdl }; assert(last_day_feb == 2018_y / feb / 28); // for 2018
  • 69. inline int number_of_days(sys_days const& first, sys_days const& last) { return (last - first).count(); } auto days = number_of_days(2018_y / apr / 1, 2018_y / dec / 25); assert(days == 268); Calender and timezone library ? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
  • 70. Calender and timezone library ? ?? ??? ?? ??? ? ?? ?? ? locate_zone : ??? ??? ?? ???? ?? ?? ? current_zone : ?? ?? ???? ?? ???? ?? ?? ? ?? ??? ? ?? ? sys_info, local_info ? zoned_traits, zoned_time ? choose, leap, link ? nonexistent_local_time ? ambiguous_local_time C++ Korea 5th Seminar C++20 Key Features Summary
  • 71. auto time = floor<std::chrono::milliseconds>(system_clock::now()); std::cout << std::left << std::setw(25) << std::setfill(' ') << "Time" << time << std::endl; auto localtime = zoned_time<std::chrono::milliseconds>(date::current_zone(), time); std::cout << std::left << std::setw(25) << std::setfill(' ') << "Local" << localtime << std::endl; Calender and timezone library ? ?? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
  • 72. auto zone_names = { "Asia/Tokyo", "Asia/Hong_Kong", "Europe/Bucharest", "Europe/Berlin", "Europe/London", "America/New_York", "Pacific/Honolulu", }; for(auto const& name : zone_names) std::cout << std::left << std::setw(25) << std::setfill(' ') << name << zoned_time<std::chrono::milliseconds>(name, localtime) << std::endl; Calender and timezone library ? ?? ??? ?? ??? ?? C++ Korea 5th Seminar C++20 Key Features Summary https://mariusbancila.ro/blog/2018/03/27/cpp20-calendars-and-time-zones/
  • 73. ??? ?? C++20? ? ?? ? Synchronized output ? char8_t ? [[likely]], [[unlikely]] attribute ? [[no_unique_address]] attribute ? constexpr ? virtual functions ? dynamic_cast ? typeid ? try-catch C++ Korea 5th Seminar C++20 Key Features Summary
  • 74. ??? ?? C++20? ? ?? ? std::remove_cvref ? std::atomic_ref ? std::atomic_shared_ptr ? std::atomic_weak_ptr ? std::destroying_delete C++ Korea 5th Seminar C++20 Key Features Summary
  • 75. C++20? ??? ?? ?? ?? ? Expansion statements ? constexpr std::vector ? std::format ? std::source_location ? std::flatmap, std::flatset ? std::byteswap ? using enum C++ Korea 5th Seminar C++20 Key Features Summary
  • 76. ?? ? C++20 ??? ??? ??? ??? ?? ?? ????. ? C++20? ???? C++11 ?? ? ??? ??? ?????. ? ??? ?? ??? ??? ?? / ?? ???? ????. ? ? ??? ?????? ??? ? ??? ? ??? ????. ? ?? C++? ??? ??? ???????, ?? ???? ???? ??? ?? ??? ?????. C++ Korea 5th Seminar C++20 Key Features Summary