목록개발 및 공부/언어 (68)
NeuroWhAI의 잡블로그
https://en.cppreference.com/w/cpp/language/structured_binding Structured binding은 C++17에서 추가된 문법입니다.한글로는 뭐라고 해야할지 모르겠네요. 구조적 바인딩?구조체나 배열 등이 가지는 멤버들을 풀어서 바인딩(변수에 할당)할 수 있게 해주는 편의 문법입니다. 가장 간단한 예를 들자면 int arr[3] = { 1, 2, 3 }; auto [a, b, c] = arr; cout
// 추상 클래스 abstract class ZeroBase { abstract fun hello() // Body 없음. } // 상속 가능 클래스 open class Base(val x: Int) : ZeroBase() { override fun hello() { // 오버라이드시 override 키워드 필수. println("Hello!") } // abstract class, interface의 요소가 아니라면 // 오버라이드가 가능하기 위해선 open 키워드가 필요. open fun test() { println("Base") } } class Derived : Base { // super(...)로 상위 클래스의 생성자 호출 가능. constructor() : super(42) construc..
https://en.cppreference.com/w/cpp/language/operator_comparison#Three-way_comparisonhttps://en.cppreference.com/w/cpp/language/default_comparisons 비교연산자...라네요...a b 일때a b면 0보다 크다는 것을 의미하는 객체(greater)를,a == b면 0을 의미하는 객체(equivalent)를 반환한다고 합니다.왜 0보다 작은 값이면 값이지 객체냐고 물으신다면 저도 모릅니다(?)int같은 타입이 반환형이 아니고 std::strong_ordering, std::weak_ordering 등의 클래스에 정의된 상수를 반환한다고 하..
https://en.cppreference.com/w/cpp/language/class_template_argument_deduction "The syntax of a user-defined deduction guide is the syntax of a function declaration with a trailing return type, except that it uses the name of a class template as the function name""user-defined deduction guide는 템플릿 클래스를 함수 이름으로 사용한다는 것만 빼면'->'를 사용해 반환형을 명시한 함수 선언 문법입니다." 이름을 좀 더 길지만 알기 쉽게 쓰자면User-defined template a..
https://en.cppreference.com/w/cpp/language/template_argument_deduction 템플릿 인자 추론은 익숙한 문법이지만 C++17부터 기능이 더 확장되었습니다.템플릿 클래스가 객체 생성의 타입으로 사용되는 경우에도 추론이 수행되도록 말이죠!이게 무슨 말이냐... 아래 코드를 보시면 바로 이해가 되실겁니다. #include using namespace std; template class Foo { public: Foo(const T& data) : data(data) { } T data; }; int main() { Foo a = 42; auto f = Foo{ a.data }; cout
https://en.cppreference.com/w/cpp/language/fold #include using namespace std; template int binaryRightFold(TArgs&&... args) { return (args - ... - 10); } template int binaryLeftFold(TArgs&&... args) { return (10 - ... - args); } int main() { cout
https://en.cppreference.com/w/cpp/thread/lock_tag https://en.cppreference.com/w/cpp/thread/lock_tag_t mutex 헤더에 정의되어 있는 이 3개의 lock tag들은 mutex를 받는 표준 라이브러리 함수나 객체가 해당 mutex를 어떻게 취급할지 지정할 수 있게 해줍니다. defer_lock : 뮤텍스를 잠그지 않습니다. try_to_lock : 뮤텍스를 잠그려고 시도합니다. (이미 잠겨있다면 대기하지 않고 실패합니다) adopt_lock : 이미 뮤텍스가 현재 스레드에 의해 잠겨있다고 가정합니다. (=잠그지 않습니다) 이걸 어디다 쓰느냐... 하실 수 있지만 생각해봅시다. 두 뮤텍스 a, b를 한번에 잠궈야할 일이 생긴다고..
https://play.rust-lang.org/?gist=99e193ae58efd33a65408ef3aea41980&version=stable&mode=debug&edition=2015 fn main() { // exclusive range for x in 0..5 { print!("{} ", x); } println!(); // inclusive range for x in 0..=5 { print!("{} ", x); } println!(); /*for x in 0...5 { print!("{} ", x); } println!();*/ //error: `...` syntax cannot be used in expressions let x = 42; match x { 0...42 => println!(..
※ 아래 내용은 스택오버플로의 글을 공부하고 정리한 내용이므로 틀린 내용이 있을 수 있습니다. 템플릿 메타프로그래밍을 이용해서 특정 타입에 특정 멤버가 있는지 컴파일 타임에 확인할 수 있는 방법이 있습니다.일단 코드부터 보시죠. #include #include template struct has_member_foo : std::false_type { }; template struct has_member_foo : std::true_type { }; class Bar { public: int bar; }; class Foo { public: explicit Foo(int); int foo; }; int main() { using namespace std; cout