David	Millington,	Bruneau	Babet,	Patrick	Scheller	
David.Millington@embarcadero.com
Day 3: 

Under the hood of the 

C++Builder IDE and Compilers
David	Millington	
David.Millington@embarcadero.com
Day 3: 

C++11 Language Deep Dive
Iterators
it = collection.begin();
Loop	until	not	equal	to	end()	–	end()	points	to	one	past	the	last	item.	
Increment	(eg	++	to	inc	by	one)	or	decrement	to	move	where	in	the	range	
the	iterator	is	pointing	to.	
for	(std::vector<int>::const_iterator	it	=	

													items.begin();	it	!=	items.end();	it++)	
Pointer	semantics:	‘dereference’	with	*	or	->,	like	a	real	pointer	to	
something.	
int	i	=	*it;	//	where	it	is	an	iterator	in	to	a	collection	of	ints
Lambdas
Anonymous	functions,	written	inline,	capture	variables,	behave	like	objects	
(can	assign	to	a	variable.)	
[] The	variable	or	capture	list		
() The	argument	list		
{} Code	
[n](int& i, this) { return i + n == this->foo; }
Lambdas
auto f = [&n](int i)
{ return i + n };
Making	the	simplest	lambda	
				[](){}	
a	method	that	captures	nothing,	is	passed	no	arguments,	and	does	nothing.	
• Neat	and	readable	
• Inline	in	code	
• Inlineable	and	performant	
• Capture	variables	by	value	or	reference	
• Behave	like	an	object
Smart Pointers
No:	
Foo* foo = new Foo();
__try {
//
} __finally {
delete foo;
}
Yes:	
{
unique_ptr<Foo> foo(
new Foo());
}
^-	foo	is	freed
Smart Pointers
Using	boost?	Move	to	shared_ptr	(very	familiar!)	and	unique_ptr	instead	of	
scoped_ptr	
In	general,	already	using	them	or	not:	
• Use	unique_ptr	where	possible	
• Use	shared_ptr	not	out	of	ease	but	when	you	want	to	share	
• Don’t	expect	automatic	threadsafety	apart	from	+/-	refcount	
• Use	shared_ptr<Foo> p = make_shared<Foo>;	and	
make_unique<T>	if	available	-	http://stackoverflow.com/questions/17902405/
how-to-implement-make-unique-function-in-c11	
• Never	write	new	or	delete
Old vs Newstd::vector<int>	items;	
items.push_back(1);	
items.push_back(2);	
items.push_back(5);	
std::map<int,	std::wstring>	map;	
map[1]	=	L"One";	
map[2]	=	L"Two";	
map[3]	=	L"Three";	
//	Demonstrate	an	algorithm	
for_each(items.begin(),	items.end(),	VectorMapFunctor(map));	
//	Print	all	vector	items	
for	(std::vector<int>::const_iterator	it	=	items.begin();	
					it	!=	items.end();	it++)	{	
	 std::wcout	<<	*it	<<	std::endl;	
}	
//	Create	and	do	something	with	a	Foo,	then	destroy	it	
Foo*	foo	=	new	Foo();	
Test(foo);	
delete	foo;	
std::vector<int>	items	{1,	2,	5};	
std::map<int,	std::wstring>	map	{	
	 {1,	L"One"},	
	 {2,	L"Two"},	
	 {3,	L"Three"}	
};	
//	Demonstrate	an	algorithm	-	now	use	a	lambda	
for_each(items.begin(),	items.end(),	
				[&map](int	n)	{	std::wcout	<<	map[n]	<<	std::endl;	});	
//	Print	all	vector	items	
for	(auto	i	:	items)	{	
				std::wcout	<<	i	<<	std::endl;	
}	
//	Create	and	do	something	with	a	Foo,	then	destroy	it	
std::unique_ptr<Foo>	foo(new	Foo());	
Test(*foo);
Definition	not	included	–

too	much	code	already
Example extensions
class Foo {
private:
int m_Bar;
void SetBar(int i) { m_Bar = i);
public:
__property Bar { read = m_Bar, write = SetBar }
}
Also	closures	(object	instance	+	method	pointer);	RTTI;	etc.
Compilers
Classic:	
• bcc32,	descendant	of	Turbo	C++,	Win32/OSX	
New	/	Clang	enhanced:	
• Based	on	Clang,	with	extensions	
• Started	with	Clang	3.1	&	Win64,	now	3.3	with	many	backports,	next	3.9	
• Win32,	Win64,	iOS32/64	(ARM),	Android	ARM,	Linux	(x64,	next	release)…	
Free:	
• The	Clang	Win32	compiler	
• https://www.embarcadero.com/free-tools/ccompiler
Q&A and Resources – C++ talk next up!
• Basics:	Books!	http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list	and	forums	like	the	C
++	G+	group:	https://plus.google.com/u/0/communities/116007775542700637383	(general	C++)	or	https://
plus.google.com/communities/118315259185736124693	(C++Builder)	
• C++	/	STL:	http://cppreference.com	
• Auto:	http://thbecker.net/articles/auto_and_decltype/section_01.html	
• Lambdas:	http://www.drdobbs.com/cpp/lambdas-in-c11/240168241	
• Smart	pointers:	http://www.acodersjourney.com/2016/05/top-10-dumb-mistakes-avoid-c-11-smart-pointers/	
• C++	Builder	
• http://docwiki.embarcadero.com/RADStudio/Berlin/en/C++11_Language_Features_Compliance_Status	
• http://docwiki.embarcadero.com/RADStudio/Berlin/en/C++11_Features_Supported_by_RAD_Studio_Clang-
enhanced_C++_Compilers	
https://www.facebook.com/cppbuilder	and	https://twitter.com/EmbarcaderoTech	
Under	the	hood	of	the	C++	compiler	and	IDE:	
a	conversation	with	Patrick	Scheller	and	Bruneau	Babet	
is	up	next,	right	after	the	Q&A!

Day 3 of C++ Boot Camp - C++11 Language Deep Dive