This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Forward iterator를 얻을 수 있는 STL 컨테이너 | |
cout << "[TEST 1] vector<string>\n"; | |
vector<string> A = {"foo", "bar", "baz"}; | |
// 참조자로 직접 A 내용 수정. | |
for (pair<size_t, string&> p : enumerate(A)) | |
cout << p.first << ": " << (p.second += p.second) << '\n'; | |
// 수정 내역 확인: 벡터 원소를 상수 참조자로 받음. | |
for (pair<size_t, const string&> p : enumerate(A)) | |
cout << p.first << ": " << p.second << '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 3. const 예제 | |
cout << "[TEST 3] const\n"; | |
const string E[] = {"foo", "bar", "baz"}; | |
// decltype(p) == pair<size_t, string const&>&& | |
// p 자체는 상수가 아니므로 인덱스 값은 변경 가능, 배열 값은 수정 불가. | |
for (auto &&p : enumerate(E)) | |
cout << (p.first += 1) << ": " << p.second << '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 5. 변수를 거치지 않고 직접 사용 | |
cout << "[TEST 5] in-place through rvalue reference\n"; | |
for (auto &&p : enumerate(range(100, 103))) | |
cout << p.first << ": " << p.second << '\n'; | |
// decltype(p) == pair<size_t, string&>&& | |
for (auto &&p : enumerate(vector<string>{"foo", "bar", "baz"})) | |
cout << p.first << ": " << (p.second += p.second) << '\n'; | |
// 함수 반환값 바로 사용 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template<typename T> | |
class range_iterator { | |
T cur_; | |
const T step_ = 1; | |
public: | |
range_iterator(T init) : cur_{init} {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2. 일반 배열 예 | |
cout << "[TEST 2] array\n"; | |
string C[] = {"foo", "bar", "baz"}; | |
// auto&&로 받는 것이 범위 기반 for 문에서 일반적이고 효율적인 방법 | |
// p 타입: pair<size_t, string&>&&, 원소 타입이 string&로 추론 | |
for (auto &&p : enumerate(C, 100)) | |
cout << p.first << ": " << (p.second += p.second) << '\n'; | |
for (auto &&p : enumerate(C, 100)) | |
cout << p.first << ": " << p.second << '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 4. 앞서 구현한 range 사용 예 | |
cout << "[TEST 4] range\n"; | |
auto &&D = range(100, 103); | |
// decltype(p) == pair<size_t, int>&& | |
for (auto &&p : enumerate(D)) | |
cout << p.first << ": " << p.second << '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 6. 초기화 리스트 | |
cout << "[TEST 6] initializer list\n"; | |
for (auto &&p : enumerate({"foo", "bar", "baz"})) | |
cout << p.first << ": " << p.second << '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool NStrideDetector::IsMergable(int64_t ea, int32_t /*size*/, const TRAINING& t) const | |
{ | |
// | |
// Note: be careful of the sign for % operation | |
// | |
int64_t abs_stride = (t.distance > 0 ? t.distance : -t.distance); | |
int64_t lb = (t.low - abs_stride < t.low ? t.low - abs_stride : t.low/*0*/); | |
int64_t ub = (t.high + abs_stride > t.high ? t.high + abs_stride : t.high/*-1*/); | |
if (/*(t.size == size) &&*/ (((t.low - ea) % abs_stride) == 0) && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'swap.bc' | |
source_filename = "swap.cpp" | |
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-apple-macosx10.12.0" | |
; Function Attrs: ssp uwtable | |
define i32 @_Z4testv() #0 { | |
entry: | |
%a = alloca i32, align 4 | |
%b = alloca i32, align 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define linkonce_odr void @void temp_swap<int>(int&, int&)(i32* %a, i32* %b) #2 { | |
entry: ; %0 | |
%0 = load i32, i32* %a, align 4 ; W %1 | |
%1 = load i32, i32* %b, align 4 ; | W | |
store i32 %1, i32* %a, align 4 ; R | | |
store i32 %0, i32* %b, align 4 ; R | |
ret void | |
} | |
define linkonce_odr void @void xor_swap<int>(int&, int&)(i32* %a, i32* %b) #2 { |
OlderNewer