Upload
minhyuk-kwon
View
50
Download
1
Embed Size (px)
Citation preview
큰요약: FOR C++PROGRAMMER
Top 20 Word Counter
CountWords.exe Alice_in_Wonderland.txt War_and_Peace.txt Dracula.txt The_Kama_Sutra.txt
The_Iliad.txt
WHAT’S NEW?
keywords
• auto, move semantics, lambda
• range-based for
• unicode, raw string literal
• concurrency
• new library
LAMBDA(계속)
대표예제
지금은?
std::sort( vec.begin(), vec.end() );
struct LengthSorter{ bool operator() ( const std::string& left, const std::string& right ){
return left.size() < right.size(); }
}
std::sort( vec.begin(), vec.end(), LengthSorter() );
LAMBDA(계속)
바로크식
직관적이나요?
컴파일에러는알아볼수있을까요?
포기하실랍니까?
std::sort( vec.begin(), vec.end(),boost::bind( &std::string::size, boost::lambda::_1 ) <boost::bind( &std::string::size, boost::lambda::_2 ) );
LAMBDA(계속)
직관적이나요?
‘캡처’ 에대해서는다음기회에...
std::sort( vec.begin(), vec.end(), []( const std::string& left, const std::string& right ){
return left.size < right.size(); } );
MOVE SEMANTIC(계속)
Widget w1;
...
// copy w1’s state to w2
Widget w2(w1);
Widget w3;
…
// move w3’s state to w4
Widget w4(std::move(w3));
MOVE SEMANTIC(계속)
Widget w1;
...
// copy w1’s state to w2
Widget w2(w1);
Widget w3;
…
// move w3’s state to w4
Widget w4(std::move(w3));
w1 w1’s state
MOVE SEMANTIC(계속)
Widget w1;
...
// copy w1’s state to w2
Widget w2(w1);
Widget w3;
…
// move w3’s state to w4
Widget w4(std::move(w3));
w1 w1’s state
w2 w1’s copy
MOVE SEMANTIC(계속)
Widget w1;
...
// copy w1’s state to w2
Widget w2(w1);
Widget w3;
…
// move w3’s state to w4
Widget w4(std::move(w3));
w1 w1’s state
w2 w1’s copy
w3 w3
MOVE SEMANTIC(계속)
Widget w1;
...
// copy w1’s state to w2
Widget w2(w1);
Widget w3;
…
// move w3’s state to w4
Widget w4(std::move(w3));
w1 w1’s state
w2 w1’s copy
w3 w3
w4
MOVE SEMANTIC(계속)
// 임시 객체는 객체 이동의 대표후보가 된다.
typedef std::vector<T> TVec;
TVec createTVec();
TVec vt;
…
vt = createTVec();
// C++98 표준에서는, 리턴 값을 복사해서 반환하고, 리턴 값은 파괴한다.
RANGE-BASED
FOR LOOPS(계속)
obj.begin() 과 obj.end() 또는 begin(obj) 과 end(obj) 가유효하면Range-based for 를지원
• 모든 C++11 컨테이너에서 지원
• 배열과 valarrays
• 초기화리스트 –아직안됨
• 정규표현식정합들 –아직안됨
CONCURRENCY
Threads
std::thread t1([]{ doSomething(); });
std::async and Futures
std::future<double> f = std::async([]{
return laterDoSomething();
})
double val = f.get();
Mutexes
std::mutex m;
{std::lock_guard<std::mutex> L(m);
// critical section
} // unlock m
…
라이브러리 강화
emplace
std::vector<Point> p;p.push_back(Point(10,20));p.emplace_back(10,20);
Container
vector::shrink_to_fitvector::data
Container
shared_ptr
Tuples
std::tuple<Name, Address, Date> person;Name name = std::get<0>(person);Address addr = std::get<1>(person);Date date = std::get<2>(person);
라이브러리 강화
tie
std::tie(name, addr, date) = info;
std::tie(name, addr, std::ignore) = info;
make_tuple
std::tuple<Name, Address, Date> f(){
return std::make_tuple(name_, addr_, date_);
}
make_tuple
• std::regex capStartRegex(“[A-Z][[:alnum:]]*”);
아직 언급하지 않은것들
Enum강화
• 전방 enum선언
• underlying type 명세
• 묵시적변환제한
제한없는 Union(멤버에대한제한)
Time 라이브러리(concurrency 를위해)
Local types allowed as template arguments
C99 호환성(long long, __func__ 등)
Inline namespace
Scoped Allocator
아직 언급하지 않은것들constexpr
User-define literals(e.g., 10_km, 30_sec)
• operator "" _km();
Relaxed POD type; new standard layout types
extern template
& and && member functions
Relaxed rules for in-class initialization of static data member.
Contextual keyword
•
Attributes
• for [[omp::parallel()]] (int i=0; i<v.size(); ++i) { // ... }
REF
What's New for Visual C++ in Visual Studio 11 Beta
http://msdn.microsoft.com/en-us/library/hh409293(v=vs.110).aspx
C++11 in wikipedia.org
http://en.wikipedia.org/wiki/C%2B%2B11
Scott Meyers, Overview of The New C++(C++11), Artima Press,
2012.