Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Config.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2023
5 *
6 * Copyright (c) 2023, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef RooFit_Config_h
14#define RooFit_Config_h
15
16// Define ROOFIT_MEMORY_SAFE_INTERFACES to change RooFit interfaces to be
17// memory safe.
18// #define ROOFIT_MEMORY_SAFE_INTERFACES
19
20#include <memory>
21
22namespace RooFit {
23
24/// An alias for raw pointers for indicating that the return type of a RooFit
25/// function is an owning pointer that must be deleted by the caller. For
26/// RooFit developers, it can be very useful to make this an alias to
27/// std::unique_ptr<T>, in order to check that your code has no memory
28/// problems. Changing this alias is equivalent to forcing all code immediately
29/// wraps the result of functions returning a RooFit::OwningPtr<T> in a
30/// std::unique_ptr<T>.
31template <typename T>
32#ifdef ROOFIT_MEMORY_SAFE_INTERFACES
33using OwningPtr = std::unique_ptr<T>;
34#else
35using OwningPtr = T *;
36#endif
37
38/// Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
39template <typename T>
40OwningPtr<T> makeOwningPtr(std::unique_ptr<T> &&ptr)
41{
42#ifdef ROOFIT_MEMORY_SAFE_INTERFACES
43 return std::move(ptr);
44#else
45 return ptr.release();
46#endif
47}
48
49/// internal helper to turn a std::unique_ptr<t> into an owningptr.
50template <typename T, typename U>
51OwningPtr<T> makeOwningPtr(std::unique_ptr<U> &&ptr)
52{
53#ifdef ROOFIT_MEMORY_SAFE_INTERFACES
54 return std::unique_ptr<T>{static_cast<T *>(ptr.release())};
55#else
56 return static_cast<T *>(ptr.release());
57#endif
58}
59
60} // namespace RooFit
61
62#endif
double T(double x)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64
OwningPtr< T > makeOwningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
Definition Config.h:40
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35