Skip to content

iceoryx_utils/internal/cxx/set.hpp🔗

Namespaces🔗

Name
iox
building block to easily create free function for logging in a library context
iox::cxx
iox::cxx::set

Source code🔗

// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_UTILS_CXX_SET_HPP
#define IOX_UTILS_CXX_SET_HPP

#include <algorithm>

namespace iox
{
namespace cxx
{
namespace set
{
template <typename Container, typename Type = typename Container::value_type>
void add(Container& container, const Type& entry)
{
    auto iter = std::find(container.begin(), container.end(), entry);
    if (iter == container.end())
    {
        container.push_back(entry);
    }
}

template <typename Container, typename Type = typename Container::value_type>
void remove(Container& container, const Type& entry)
{
    auto iter = std::find(container.begin(), container.end(), entry);
    if (iter != container.end())
    {
        container.erase(iter);
    }
}

template <typename Container, typename Type = typename Container::value_type>
bool hasElement(Container& container, const Type& entry)
{
    auto iter = std::find(container.begin(), container.end(), entry);
    return iter != container.end();
}

template <typename Container>
Container& unify(Container& set1, const Container& set2)
{
    for (auto& element : set2)
    {
        add(set1, element);
    }
    return set1;
}

} // namespace set
} // namespace cxx
} // namespace iox

#endif // IOX_UTILS_CXX_SET_HPP

Updated on 17 June 2021 at 11:15:26 CEST