«c++11» 태그된 질문

C ++ 11로 컴파일해야하는 코드에이 태그를 사용하십시오 (C ++ 14 이상에서 도입 된 기능을 사용하지 않음).

5
람다의 C ++ 삼항 할당
다음 스 니펫이 컴파일되지 않는 이유는 무엇입니까? "오류 : 피연산자? : 다른 유형이 있습니다"라는 오류가 표시됩니다. auto lambda1 = [&](T& arg) { ... }; auto lambda2 = [&](T& arg) { ... }; auto lambda = condition ? lambda1 : lambda2;


2
명시 적으로 반환 유형을 명시하더라도 람다에 대한 호출은 모호합니다.
람다의 유형을 결정할 수있는 경우 오버로드 된 함수는 두 함수를 모두 가져 와야합니다 std::function((잘못된 경우 수정하십시오). 질문은 다음과 같습니다. 정의 되었습니까? ( [&]() -> Type {}) 현재 솔루션의 경우 참조 기준 캡처가 필요하므로 코드에 논리가 포함되어 있습니다. 다음 예제는 문제점을 설명합니다. #include <iostream> #include <string> #include <functional> void do_some(std::function<void(int)> thing) …

2
C ++ 템플릿 템플릿 인수 유형 공제
문자열 컨테이너를 통해 패턴 일치를 찾아 인쇄하는 코드가 있습니다. 템플릿 화 된 foo 함수에서 인쇄가 수행됩니다. 코드 #include <iostream> #include <algorithm> #include <iterator> #include <vector> #include <string> #include <tuple> #include <utility> template<typename Iterator, template<typename> class Container> void foo(Iterator first, Container<std::pair<Iterator, Iterator>> const &findings) { for (auto const &finding : findings) …

3
nullptr을 uintptr_t로 변환 할 수 있습니까? 다른 컴파일러는 동의하지 않습니다
이 프로그램을 고려하십시오 : #include <cstdint> using my_time_t = uintptr_t; int main() { const my_time_t t = my_time_t(nullptr); } msvc v19.24로 컴파일하지 못했습니다. <source>(5): error C2440: '<function-style-cast>': cannot convert from 'nullptr' to 'my_time_t' <source>(5): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral …
10 c++  c++11  gcc  visual-c++  clang 

3
다음과 같은 경우 종속 유형에 typename을 사용할 필요가없는 이유는 무엇입니까?
유형의 참조를 제거하는 방법에 대해 읽었 습니다 . 다음 예제를 제공합니다. #include <iostream> // std::cout #include <type_traits> // std::is_same template<class T1, class T2> void print_is_same() { std::cout << std::is_same<T1, T2>() << '\n'; } int main() { std::cout << std::boolalpha; print_is_same<int, int>(); print_is_same<int, int &>(); print_is_same<int, int &&>(); print_is_same<int, std::remove_reference<int>::type>(); // …

1
인스턴스를 만들지 않고 std :: array <T, N>의 요소 수를 얻는 방법은 무엇입니까?
이 std::array&lt;T, N&gt;::size()있지만 정적이 아니므로의 인스턴스가 필요합니다 std::array. (는 IS는 반환 값을 얻을 수있는 방법이 있습니까 N의를 std::array&lt;T, N&gt;배열의 인스턴스를 생성하지 않고)는? 일반 배열의 경우을 사용할 수 sizeof있었지만 이것이 sizeof(std::array&lt;T, N&gt;) == N * sizeof(T)사실 이라는 보장은 없습니다 .
9 c++  arrays  c++11  sizeof 

2
스레드 안전 규칙에서 제안한 비 const 인수로 생성자를 복사 하시겠습니까?
레거시 코드에 래퍼가 있습니다. class A{ L* impl_; // the legacy object has to be in the heap, could be also unique_ptr A(A const&amp;) = delete; L* duplicate(){L* ret; legacy_duplicate(impl_, &amp;L); return ret;} ... // proper resource management here }; 이 레거시 코드에서 객체를 "중복"하는 함수는 스레드로부터 안전하지 않으므로 (같은 …

2
안전한 암호화 키를 위해 std :: array에 사용자 지정 할당자를 사용할 수 있습니까?
std::array스택에 완전히 할당 된 것을 알고 있지만이 질문은 두 가지 사항이 필요한 보안 문제로 인해 발생합니다. std::array파괴시 데이터는 제로화되거나 무작위 화됩니다. 충돌이나 스왑 메모리에 디스크로 가지 않도록 데이터 std::array가 잠 깁니다 . 일반적으로와 함께 std::vector솔루션은 이러한 작업 을 수행 하는 사용자 지정 할당자를 만드는 것 입니다. 그러나에 std::array대해이 작업을 수행하는 …
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.