kick
/Users/morten/Programmering/cpp/kick/src/kick/core/cpp_ext.h
00001 //
00002 //  cpp_ext.h
00003 //  KickCPP
00004 //
00005 //  Created by Morten Nobel-Jørgensen on 10/14/13.
00006 //  Copyright (c) 2013 Morten Nobel-Joergensen. All rights reserved.
00007 //
00008 
00009 #pragma once
00010 
00011 // make_unique<T>(args...)
00012 // make_unique<T[]>(n)
00013 // make_unique<T[N]>(args...) = delete
00014 
00015 #include <cstddef>
00016 #include <memory>
00017 #include <type_traits>
00018 #include <utility>
00019 
00020 namespace kick {
00021 
00022     template<class T> struct _Unique_if {
00023         typedef std::unique_ptr<T> _Single_object;
00024     };
00025     
00026     template<class T> struct _Unique_if<T[]> {
00027         typedef std::unique_ptr<T[]> _Unknown_bound;
00028     };
00029     
00030     template<class T, size_t N> struct _Unique_if<T[N]> {
00031         typedef void _Known_bound;
00032     };
00033     
00034     template<class T, class... Args>
00035     typename _Unique_if<T>::_Single_object
00036     make_unique(Args&&... args) {
00037         return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
00038     }
00039     
00040     template<class T>
00041     typename _Unique_if<T>::_Unknown_bound
00042     make_unique(size_t n) {
00043         typedef typename std::remove_extent<T>::type U;
00044         return std::unique_ptr<T>(new U[n]());
00045     }
00046     
00047     template<class T, class... Args>
00048     typename _Unique_if<T>::_Known_bound
00049     make_unique(Args&&...) = delete;
00050 
00051 }
 All Classes Functions Variables