1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 template<typename U
, U x
>
20 typedef struct { char a
[2]; } no
;
23 static yes
& check_sig(U
*, test
<U
* (U::*)() const, &U::clone
>* = 0);
25 static no
& check_sig(...);
29 value
= sizeof(check_sig
<T
>(0)) == sizeof(yes
)
33 template<typename T
, bool HasClone
>
36 static T
* clone(T
* const other
)
43 struct cloner
<T
, true>
45 static T
* clone(T
* const other
)
47 return other
->clone();
53 /** Creates a new copy of the passed object.
54 If other is 0, just returns 0. Otherwise, if other has function
55 named clone with signature T* (T::*)() const, the function is called.
56 Otherwise, copy constructor is used.
58 @returns 0 or newly allocated object
61 T
* clone(T
* const other
)
63 return other
? ::detail::cloner
<T
, ::detail::has_clone
<T
>::value
>::clone(other
) : 0;
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */