From 59c1eebf9f0bf80bfec197fcf443e96805f9801e Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Fri, 5 Nov 2021 18:03:46 +0900 Subject: [PATCH] [Trivial] Use if instead of template 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 --- nntrainer/tensor/tensor_pool.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nntrainer/tensor/tensor_pool.cpp b/nntrainer/tensor/tensor_pool.cpp index b262137..b65f634 100644 --- a/nntrainer/tensor/tensor_pool.cpp +++ b/nntrainer/tensor/tensor_pool.cpp @@ -24,13 +24,6 @@ namespace nntrainer { /** - * @brief lambda overload helper - * - */ -template struct overloaded_ : Ts... { using Ts::operator()...; }; -template overloaded_(Ts...)->overloaded_; - -/** * @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; + if constexpr (std::is_same_v) { + return 0u; + } else if constexpr (std::is_same_v) { + return s.offset; + } + return 0u; + }, + pool[name_map.at(shared_name)].details); adjusted_offset += offset; NNTR_THROW_IF(spec.tensor->getDim().getDataLen() < -- 2.7.4