mirror of
https://github.com/vtil-project/VTIL-Core
synced 2026-08-17 08:23:03 -04:00
Implementing tuple enumeration/visiting.
This commit is contained in:
parent
54ebdb0e9d
commit
f87110f3d8
5 changed files with 53 additions and 1 deletions
|
|
@ -56,6 +56,7 @@ add_library(${PROJECT_NAME} STATIC
|
|||
util/zip.hpp
|
||||
util/colony.hpp
|
||||
util/object_pool.hpp
|
||||
util/tuple_visit.hpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC includes)
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@
|
|||
<ClInclude Include="util\reverse_iterator.hpp" />
|
||||
<ClInclude Include="util\sinkhole.hpp" />
|
||||
<ClInclude Include="util\stack_container.hpp" />
|
||||
<ClInclude Include="util\tuple_visit.hpp" />
|
||||
<ClInclude Include="util\zip.hpp" />
|
||||
<ClInclude Include="util\variant.hpp" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -184,6 +184,9 @@
|
|||
<ClInclude Include="util\object_pool.hpp">
|
||||
<Filter>Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="util\tuple_visit.hpp">
|
||||
<Filter>Utility</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="io\logger.cpp">
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@
|
|||
#include "../../util/reverse_iterator.hpp"
|
||||
#include "../../util/conditional_lock.hpp"
|
||||
#include "../../util/numeric_iterator.hpp"
|
||||
#include "../../util/multivariate.hpp"
|
||||
#include "../../util/multivariate.hpp"
|
||||
#include "../../util/tuple_visit.hpp"
|
||||
46
VTIL-Common/util/tuple_visit.hpp
Normal file
46
VTIL-Common/util/tuple_visit.hpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2020 Can Boluk and contributors of the VTIL Project
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of mosquitto nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
namespace vtil
|
||||
{
|
||||
template<typename T, typename Fn, size_t... I>
|
||||
static void tuple_visit( const T& obj, Fn callable, std::index_sequence<I...> )
|
||||
{
|
||||
static constexpr auto ignore = [ ] ( ... ) {};
|
||||
ignore( ( callable( std::get<I>( obj ) ), 0 )... );
|
||||
}
|
||||
|
||||
template<typename Fn, typename... Tx>
|
||||
static void tuple_visit( const std::tuple<Tx...>& obj, Fn&& callable )
|
||||
{
|
||||
return tuple_visit( obj, std::forward<Fn>( callable ), std::index_sequence_for<Tx...>{} );
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue