[Trivial] Use if instead of template
authorJihoon Lee <jhoon.it.lee@samsung.com>
Fri, 5 Nov 2021 09:03:46 +0000 (18:03 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 16 Nov 2021 07:46:20 +0000 (16:46 +0900)
This patch changes template to if constexpr. There seems to be false
positive with cppcheck with previous implementation, but do not need to
bother by a code used only in very small places.

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/tensor/tensor_pool.cpp

index b262137..b65f634 100644 (file)
 namespace nntrainer {
 
 /**
- * @brief lambda overload helper
- *
- */
-template <class... Ts> struct overloaded_ : Ts... { using Ts::operator()...; };
-template <class... Ts> overloaded_(Ts...)->overloaded_<Ts...>;
-
-/**
  * @brief     Request tensor with the given spec
  *
  * @note returns empty tensor which will be filled when allocate is called.
@@ -75,10 +68,17 @@ Tensor *TensorPool::requestPrerequestedTensor(
   const std::string &shared_name, const Tensor::Initializer &init,
   const unsigned int offset) {
   auto &spec = getSourceSpec(shared_name);
-  unsigned adjusted_offset =
-    std::visit(overloaded_{[](const SourceDetails &s) { return 0u; },
-                           [](const DependentDetails &s) { return s.offset; }},
-               pool[name_map.at(shared_name)].details);
+  unsigned adjusted_offset = std::visit(
+    [](const auto &s) {
+      using T = std::decay_t<decltype(s)>;
+      if constexpr (std::is_same_v<T, SourceDetails>) {
+        return 0u;
+      } else if constexpr (std::is_same_v<T, DependentDetails>) {
+        return s.offset;
+      }
+      return 0u;
+    },
+    pool[name_map.at(shared_name)].details);
   adjusted_offset += offset;
 
   NNTR_THROW_IF(spec.tensor->getDim().getDataLen() <