2 minute read

Categories:

Tags:

๋ฐฐ์šด๊ฒƒ๋“ค

2022 Aug 13

static ๋ณ€์ˆ˜ ->๊ฐ์ฒด ๋ณ„๋กœ ํ• ๋‹น๋˜์ง€ ์•Š๊ณ  ํด๋ž˜์Šค์˜ ๋ชจ๋“  ๊ฐ์ฒด๊ฐ€ ๊ณต์œ ํ•˜๋Š” ๋งด๋ฒ„๋ฅผ ์˜๋ฏธํ•จ

์ •์  ๋งด๋ฒ„ ํ•จ์ˆ˜ -> ํ•ด๋‹น ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ ๋„, ํด๋ž˜์Šค ์ด๋ฆ„๋งŒ์œผ๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Œ

  • \1. ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  ํด๋ž˜์Šค ์ด๋ฆ„๋งŒ์œผ๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
  • ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, this ํฌ์ธํ„ฐ๋ฅผ ๊ฐ€์ง€์ง€ ์•Š๋Š”๋‹ค
  • ํŠน์ • ๊ฐ์ฒด์™€ ๊ฒฐํ•ฉํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, ์ •์  ๋งด๋ฒ„ ๋ณ€์ˆ˜๋ฐ–์— ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

2022 Aug 14

cpp unique function.

// C++ program to demonstrate the use of std::unique
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    vector<int> v = { 1, 1, 3, 3, 3, 10, 1, 3, 3, 7, 7, 8 }, i;
  
    vector<int>::iterator ip;
  
    // Using std::unique
    ip = std::unique(v.begin(), v.begin() + 12);
    // Now v becomes {1 3 10 1 3 7 8 * * * * *}
    // * means undefined
  
    // Resizing the vector so as to remove the undefined terms
    v.resize(std::distance(v.begin(), ip));
  
    // Displaying the vector after applying std::unique
    for (ip = v.begin(); ip != v.end(); ++ip) {
        cout << *ip << " ";
    }
  
    return 0;//output: 1 3 10 1 3 7 8
}

Input ๋ฐ›๋Š”๋ฒ•

input์ด โ€œinput1 input2โ€ํ˜•์‹์ผ๋–„

for (const auto& s : report) {
        stringstream in(s);
        string a, b; 
        in >> a >> b;
        v.push_back({ Conv[a], Conv[b] });
    }

reverse_copy(filtered_string.begin(), filtered_string.end(), reversed_string.begin());

int isalnum(int c) -> Checks whether c is either a decimal digit or an uppercase or lowercase letter.

tolower ->change to lower case letter

->` is defined in terms of `.

That is, a->b is equivalent to (*a).b and so youโ€™ll obviously get the same results.

-> exists for convenience.

2022 Aug 15

void unsubscribe(Observer<T>& observer)
{
	observers.erase(
		remove(observers.begin(), observers.end(), observer),
		observers.end()
	);
}

2022 Aug 17

์Šค๋งˆํŠธ ํฌ์ธํ„ฐ

uniqueํฌ์ธํ„ฐ๋Š” move๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์†Œ์œ ๊ถŒ์„ ์ด์ „ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋ณต์‚ฌ๋Š” ๋ถˆ๊ฐ€ํ•˜๋‹ค

์†Œ์œ ๊ถŒ์ด ์ด์ „๋˜๋ฉด ์ด์ „ unique_ptr์ธ์Šคํ„ด์Šค๋Š” ๋”๋Š” ํ•ด๋‹น ๊ฐ์ฒด๋ฅผ ์†Œ์œ ํ•˜์ง€ ์•Š๊ฒŒ ์žฌ์„ค์ •๋œ๋‹ค

shared_ptr์€ ํ•˜๋‚˜์˜ ํŠน์ • ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ๊ฐ€ ์ด ๋ช‡ ๊ฐœ์ธ์ง€๋ฅผ ์ฐธ์กฐํ•˜๋Š” ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ์ž…๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ฐธ์กฐ ํšŸ์ˆ˜(reference count)๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

weak_ptr์€ ํ•˜๋‚˜ ์ด์ƒ์˜ shared_ptr ์ธ์Šคํ„ด์Šค๊ฐ€ ์†Œ์œ ํ•˜๋Š” ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์ œ๊ณตํ•˜์ง€๋งŒ, ์†Œ์œ ์ž์˜ ์ˆ˜์—๋Š” ํฌํ•จ๋˜์ง€ ์•Š๋Š” ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ์ž…๋‹ˆ๋‹ค.

shared_ptr์€ ์ฐธ์กฐ ํšŸ์ˆ˜(reference count)๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋™์ž‘ํ•˜๋Š” ์Šค๋งˆํŠธ ํฌ์ธํ„ฐ์ž…๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์„œ๋กœ๊ฐ€ ์ƒ๋Œ€๋ฐฉ์„ ๊ฐ€๋ฆฌํ‚ค๋Š” shared_ptr๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋ฉด, ์ฐธ์กฐ ํšŸ์ˆ˜๋Š” ์ ˆ๋Œ€ 0์ด ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ฉ”๋ชจ๋ฆฌ๋Š” ์˜์›ํžˆ ํ•ด์ œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ์„œ๋กœ๊ฐ€ ์ƒ๋Œ€๋ฐฉ์„ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์„ ์ˆœํ™˜ ์ฐธ์กฐ(circular reference)๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

weak_ptr์€ ๋ฐ”๋กœ ์ด๋Ÿฌํ•œ shared_ptr ์ธ์Šคํ„ด์Šค ์‚ฌ์ด์˜ ์ˆœํ™˜ ์ฐธ์กฐ๋ฅผ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

2022 Aug 29

Helpful string functions: isalnum, tolower

2022 Oct 12

removing duplicates:

sort(v.begin(), v.end());
v.erase(std::unique(v.begin(),v.end()), v.end())

stack grows because of page fault exception.

2022 Oct 27

glad์™€ glfw๋ฅผ ๊ฐ™์ด ์‚ฌ์šฉํ• ๋•Œ ์ฃผ์˜ํ•ด์•ผํ• ๊ฒƒ๋“ค

https://stackoverflow.com/questions/62756734/glad-causes-glfwswapbuffers-to-return-error-message

2022 Nov 7

c++ 11 ์ด์ƒ๋ฒ„์ „์—์„œ ์—ฌ๋Ÿฌ์ค„์— ๊ฑธ์นœ ์ŠคํŠธ๋ง์„ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ฝ์„์ˆ˜ ์žˆ๋‹ค

  std::string vertexShader =R"glsl(
		#version 330 core

		layout(location = 0) in vec4 position;

		void main(){
		   gl_Position = position;
		}
		)glsl";

2022 Nov 9

cpp 20์—์„œ vector slicing ํ•˜๋Š”๋ฒ•

https://godbolt.org/z/qeaxvjdbj

2022 Nov 27

clion ์•ˆ์—์„œ relative path๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„  Edit Configuration ์— ๋“ค์–ด๊ฐ€์„œ working directory๋ฅผ ์ง€์ •ํ•ด ์ค˜์•ผํ•œ๋‹ค.

2023 Feb 02

When do we use no except: https://stackoverflow.com/questions/10787766/when-should-i-really-use-noexcept

Leave a comment