OpenMS
MacrosTest.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hannes Roest $
6 // $Authors: Philippe M. Groarke, Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 // See https://philippegroarke.com/posts/2018/easy_defensive_programming/
10 // https://github.com/p-groarke/defensive_cpp
11 
12 #pragma once
13 #include <type_traits>
14 
15 namespace OpenMS
16 {
17  // no constexpr lambdas in C++11, therefore we have to use functions
18  namespace Test
19  {
20  template <class T>
21  constexpr bool fulfills_rule_of_5()
22  {
23  static_assert(std::is_destructible<T>::value, "T : must be destructible");
24  static_assert(std::is_copy_constructible<T>::value, "T : must be copy constructible");
25  static_assert(std::is_move_constructible<T>::value, "T : must be move constructible");
26  static_assert(std::is_copy_assignable<T>::value, "T : must be copy assignable");
27  static_assert(std::is_move_assignable<T>::value, "T : must be move assignable");
28 
29  return std::is_destructible<T>::value &&
30  std::is_copy_constructible<T>::value &&
31  std::is_move_constructible<T>::value &&
32  std::is_copy_assignable<T>::value &&
33  std::is_move_assignable<T>::value;
34  }
35 
36  template <class T>
37  constexpr bool fulfills_rule_of_6()
38  {
39  static_assert(fulfills_rule_of_5<T>(), "T : must fulfill rule of 5");
40  static_assert(std::is_default_constructible<T>::value, "T : must be default constructible");
41 
42  return fulfills_rule_of_5<T>() &&
43  std::is_default_constructible<T>::value;
44  }
45 
46  template <class T>
47  constexpr bool fulfills_fast_vector()
48  {
49  static_assert( (std::is_trivially_copy_constructible<T>::value && std::is_trivially_destructible<T>::value) ||
50  std::is_nothrow_move_constructible<T>::value,
51  "T : doesn't fulfill fast vector (trivially copy constructible " \
52  "and trivially destructible, or nothrow move constructible)");
53 
54  return (std::is_trivially_copy_constructible<T>::value && std::is_trivially_destructible<T>::value) ||
55  std::is_nothrow_move_constructible<T>::value;
56  };
57  }
58 }
59 
constexpr bool fulfills_fast_vector()
Definition: MacrosTest.h:47
constexpr bool fulfills_rule_of_5()
Definition: MacrosTest.h:21
constexpr bool fulfills_rule_of_6()
Definition: MacrosTest.h:37
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19