VisionCpp  0.0.1
static_if.hpp
Go to the documentation of this file.
1 // This file is part of VisionCpp, a lightweight C++ template library
2 // for computer vision and image processing.
3 //
4 // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
5 //
6 // Contact: visioncpp@codeplay.com
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 
20 /// \file static_if.hpp
21 /// \brief This file provides a set of static_if functions used at to calculate
22 /// the result of if statement at compile time
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_STATIC_IF_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_STATIC_IF_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 namespace tools {
30 /// \struct IfNode
31 /// \brief This struct is used to determine whether or not an expression node is
32 /// a leafNode
33 /// template parameters
34 /// \tparam T is the type of the expression tree
35 template <typename T>
36 struct IfNode {
37  static constexpr bool Is_LeafNode = false;
38 };
39 /// \brief specialisation of the IfNode when the node is leafNode
40 template <typename Nested, size_t LVL>
41 struct IfNode<LeafNode<Nested, LVL>> {
42  static constexpr bool Is_LeafNode = true;
43 };
44 
45 /// \struct StaticIf
46 /// \brief It is used to select either of the input type based the Conds
47 /// template parameters
48 /// \tparam Conds : determines the condition
49 /// \tparam T1 : first input type
50 /// \tparam T2 : second input type
51 template <bool Conds, typename T1, typename T2>
52 struct StaticIf {
53  using Type = T1;
54  using LostType = T2;
55 };
56 /// \brief specialisation of the StaticIf when the condition is false
57 template <typename T1, typename T2>
58 struct StaticIf<false, T1, T2> {
59  using Type = T2;
60  using LostType = T1;
61 };
62 /// \struct StaticIf
63 /// \brief It is used to select either of the template constant variable based
64 /// the Conds
65 /// template parameters
66 /// \tparam Conds : determines the condition
67 /// \tparam X : first constant variable
68 /// \tparam Y : second constant type
69 template <bool Conds, size_t X, size_t Y>
70 struct IfConst {
71  static constexpr size_t Value = X;
72 };
73 /// specialisation of the IfConst when the condition is false
74 template <size_t X, size_t Y>
75 struct IfConst<false, X, Y> {
76  static constexpr size_t Value = Y;
77 };
78 
79 } // tools
80 } // internal
81 } // visioncpp
82 #endif // VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_STATIC_IF_HPP_
VisionCpp namespace.
Definition: sycl/device.hpp:24
the definition is in LeafNode.
Definition: leaf_node.hpp:38
static constexpr size_t Value
Definition: static_if.hpp:71
This struct is used to determine whether or not an expression node is a leafNode template parameters.
Definition: static_if.hpp:36
static constexpr bool Is_LeafNode
Definition: static_if.hpp:37
It is used to select either of the input type based the Conds template parameters.
Definition: static_if.hpp:52