Skip to main content
added 3 characters in body
Source Link
Loki Astari
  • 96.6k
  • 5
  • 125
  • 338

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<std::size_t> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<std::size_t> searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<std::size_t> result;
    
    for(std::size_t  index = 0; begin != end; ++begin, ++index)
    {
        if ((*begin) == findFor)
        {
            result.push_backemplace_back(index);
        }
    }
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<std::size_t> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<std::size_t> searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<std::size_t> result;
    
    for(std::size_t  index = 0; begin != end; ++begin, ++index)
    {
        if ((*begin) == findFor)
        {
            result.push_back(index);
        }
    }
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<std::size_t> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<std::size_t> searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<std::size_t> result;
    
    for(std::size_t  index = 0; begin != end; ++begin, ++index)
    {
        if ((*begin) == findFor)
        {
            result.emplace_back(index);
        }
    }
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.

added 61 characters in body
Source Link
Loki Astari
  • 96.6k
  • 5
  • 125
  • 338

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<V>vector<std::size_t> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<typename std::iterator_traits<I>vector<std::value_type> 
   size_t> searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<typename std::iterator_traits<I>vector<std::value_type>size_t> result;
    
    for(std::copy_if(size_t  index = 0; begin, end!= end; ++begin, std::back_inserter(result++index), 
 std::equal   {
        if ((*begin) == findFor)
        {
            result.push_back(index);
        }
    }
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<V> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<typename std::iterator_traits<I>::value_type> 
    searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<typename std::iterator_traits<I>::value_type> result;
    std::copy_if(begin, end, std::back_inserter(result), std::equal(findFor));
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<std::size_t> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<std::size_t> searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<std::size_t> result;
    
    for(std::size_t  index = 0; begin != end; ++begin, ++index) 
    {
        if ((*begin) == findFor)
        {
            result.push_back(index);
        }
    }
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.

Source Link
Loki Astari
  • 96.6k
  • 5
  • 125
  • 338

Everything @Jerry said.

In addition I echo the view of @Bizket but disagree with the better solution.

C++ emphasize the use of concepts (the exact type does not matter, the interface of the type is what matters when designing). You loop over an C-array and Bizkit says you should update to specific C++ container types. I would suggest that you update to use generic C++ container types (as long as your input acts like a container) that support the interface you need (then let the compiler verify its correct).

Also C++ tends to use Iterators to define ranges (or containers). This allows you to be more flexible issue.

Also why are you constraining your algorithm to int? Just make it generic then you don't need to write it again for other types.

template<typename C, typename V>
std::vector<V> searchList(C const& theContainer, V const& findFor)
{
    return searchList(std::begin(theContainer), std::end(theContainer), findFor);
}
template<typename I>
std::vector<typename std::iterator_traits<I>::value_type> 
    searchList(I begin, I end, std::iterator_traits<I>::value_type const& findFor)
{
    std::vector<typename std::iterator_traits<I>::value_type> result;
    std::copy_if(begin, end, std::back_inserter(result), std::equal(findFor));
    return result;
}

Note: the exact type does not matter. Type is still the most important thing of a C++ object. But the exact type does not matter just that it has a specific type and that you can determine the interface of the type at compile time.