std::launch::async를 지정한 경우, 해당 함수를 즉시 호출한다.

#include <iostream>
#include <chrono>
#include <future>

string func(string str)
{
	cout << str << '\n';
	return "5초 끝";
}


int main()
{
	cout << "시작" << '\n';
    
    std::future<string> f1 = std::async(std::launch::async, func, "5초 세기 시작");
    
    std::this_thread::sleep_for(std::chrono::seconds(5));
    
    f1.get();
}

 

아래와 같이 출력된다.

더보기

시작

5초 세기 시작

(5초 후)

5초 끝

 

 

std::launch::deferred 를 지정한 경우, get()이나 wait()을 통해 함수가 실행된다.

 

...

string func(string str)
{
	cout << str << '\n';
    return "5초 끝";
}

int main()
{
	std::cout << "시작" << '\n';
    
    std::future<string> f1 = std::async(std::launch::deferred, func, "5초 세기 시작");
    
    std::this_thread::wait_for(std::chrono::seconds(5));
    
    std::cout << f1.get() << '\n';
}

 

아래와 같이 출력된다.

더보기

시작

(5초 후)

5초 세기 시작

5초 끝

 

'개인 공부 > C++' 카테고리의 다른 글

std::move  (0) 2023.05.15
std::any_of  (0) 2023.05.15
std::find_if  (0) 2023.05.15
std::remove_if  (0) 2023.05.15
E1735 바깥쪽 함수의 지역 변수는 캡처 목록에 있지 않는 한 람다 본문에서 참조할 수 없습니다.  (0) 2022.11.21

원격 데스크톱 연결 시 " credssp 암호화 oracle 수정 때문일 수 있습니다" 오류 메시지 출력됨.

 

https://velog.io/@ysy3285/Windows11-%EC%9B%90%EA%B2%A9-%EB%8D%B0%EC%8A%A4%ED%81%AC%ED%86%B1-%EC%97%B0%EA%B2%B0%EC%8B%9C-CredSSP-%EC%95%94%ED%98%B8%ED%99%94-Oracle-%EC%88%98%EC%A0%95-%EB%95%8C%EB%AC%B8%EC%9D%BC-%EC%88%98-%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4-%EC%98%A4%EB%A5%98

 

 

map에 key 값이 존재하지 않을 때, [_key] 접근을 하게 되면 새로운 key-value 쌍이 생성된다.

key 값은 _key로, value는 기본 초기값을 가진다. (int의 경우 0, string의 경우 ""이다.)

 

 

 

 

 

 

emplace()

  • 원소를 삽입할 때 중복된 key 값의 원소가 있더라도 새로운 원소를 추가한다. 
  • 이미 있는 key 값의 원소를 갱신하고 싶지 않고 새로 추가하고 싶을 때 유용하다.
  • 원소를 생성자에 매개변수로 전달하는 방식으로 추가한다. 따라서 std::map 내부에서 직접 생성하게 된다. 
  • 임시 객체 생성과 복사를 최소화하여 효율적인 원소 추가를 지원한다.

 

insert()

  • 원소를 삽입할 때 이미 중복된 key를 가진 원소가 있다면 삽입되지 않는다.
  • 이미 있는 key 값을 사용하고는 싶지만 갱신하고 싶지 않을 때 유용하다.
  • std::make_pair이나 value_type으로 값을 생성하여 insert를 해야 한다.

 

'개인 공부 > 자료구조' 카테고리의 다른 글

map, unordered_map  (0) 2022.07.19
std::map  (0) 2022.05.26
std::priority_queue  (0) 2022.05.19
std::queue  (0) 2022.05.19
STL iterator  (0) 2021.06.10

쿼리로는 불가능하고, 디자인을 통해서 중간에 삽입이 가능하다.

아래에 위치하고자 하는 행의 ▶를 우클릭해서 '열 삽입'을 누르면 된다.

 

select ~

order by newid();

삽입할 위치와 값을 전달 받아서 해당 위치에 원소를 삽입한다.

#include <iostream>
#include <list>

int main() {
    std::list<int> list1{ 1, 2, 3 };
    std::list<int> list2{ 4, 5, 6 };
    list1.insert(list1.end(), list2.begin(), list2.end());
    
    for (const auto& value : list1) {
        std::cout << value << " ";
    }
    std::cout << std::endl;

    return 0;
}

+ Recent posts