Skip to content

Instantly share code, notes, and snippets.

@kaorun55
Created August 13, 2012 08:26
Show Gist options
  • Save kaorun55/3338219 to your computer and use it in GitHub Desktop.
Save kaorun55/3338219 to your computer and use it in GitHub Desktop.
C++11
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
class hoge
{
public:
hoge()
{
std::cout << __FUNCTION__ << " ctor:" << std::hex << this << std::endl;
}
hoge(const hoge& rhs)
{
std::cout << __FUNCTION__ << " copy :" << std::hex << this << std::endl;
}
hoge(hoge&& rhs)
{
std::cout << __FUNCTION__ << " move :" << std::hex << this << std::endl;
}
};
// VS 2012
#if _MSC_VER >= 1700
enum class EnumType : unsigned int
{
Val1,
Val2,
};
#endif
class bar
{
public:
bar() //= default
{
}
//bar(const bar& rhs) = delete;
//int a = 1;
};
// extened friend
template< typename T >
class moge
{
friend T;
};
//extern template class moge<int>;
#include <utility>
#define typeof(X) std::identity<decltype(X)>::type
void main()
{
// http://mwlab.net/2010/08/directive.html
std::cout << "_MSC_VER:" << _MSC_VER << std::endl;
// static_assert
static_assert( sizeof(int) == sizeof(int*), "not pointer size" );
// auto & decltype
//auto ret = std::max( 1, 2 );
auto ret = std::max( 1.0, 2.0 );
decltype( ret ) b;
// http://d.hatena.ne.jp/faith_and_brave/20080701/1214902856
std::list<int> v;
//std::vector<int> v;
v.push_back( 1 );
v.push_back( 2 );
v.push_back( 3 );
v.push_back( 5 );
v.push_back( 8 );
for ( auto i : v ) {
std::cout << i << std::endl;
}
//typeof(v)::iterator it = v.begin();
//int aa[] = { 1, 2, 3, 5, 8 };
//for ( auto b : aa ) {
// std::cout << b << std::endl;
//}
// move constructor
hoge h;
hoge hh( h );
hoge hhh( std::move( h ) );
// nullptr
int *p = nullptr;
// Strongly Typed Enums
// exception_ptr
// http://dev.activebasic.com/egtra/2011/09/09/394/
//std::exception_ptr ex;
//std::rethrow_exception( ex );
// long long
static_assert( sizeof(long long) == 8, "long long is 8bytes" );
// local and unnamed template types
struct test
{
public:
void operator() ( int val )
{
std::cout << val << "," << std::endl;
}
};
int a[] = { 1, 2, 3, 5, 8 };
std::for_each( &a[0], &a[5], test() );
// ラムダ
std::for_each( &a[0], &a[5], []( int a ){ std::cout << a << std::endl; } );
bar bb;
//bar bbb( bb );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment