Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
clone.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include "type_traits.hpp"
27
28namespace ext {
29
40template < class T >
41auto clone ( T && tmp ) {
42 if constexpr ( ext::has_clone < T >::value && ! std::is_final_v < T > )
43 return std::forward < T > ( tmp ).clone ( );
44 else
45 return new typename std::decay < T >::type ( std::forward < T > ( tmp ) );
46}
47
48} /* namespace ext */
49
Definition: sigHandler.cpp:20
auto clone(T &&tmp)
Wrapper around clone by means of using copy constructor or clone method if available.
Definition: clone.hpp:41
Type trait to determine existence of clone method. A boolean field namd value is set to true if provi...
Definition: type_traits.hpp:39