[cfe-dev] missing optimization opportunity for const std::vector compared to std::array

dennis luehring dl.soluz at gmx.net
Wed May 28 09:21:36 PDT 2014


another bigger example - clang does not get result/remove allocs, but the
resulting code is much smaller then gcc 4.9.0

---------
#include <vector>
#include <numeric>
#include <array>

//#define USE_STD_ARRAY
#define BIGGER

#if defined(USE_STD_ARRAY)
typedef std::array<int,2> container_t;
#else
typedef std::vector<int> container_t;
#endif

int main()
{
#if defined(BIGGER)  
  const container_t a{1,2};
  const container_t b{4,5};
  const container_t ints
  {
    std::accumulate(a.begin(),a.end(),1),
    std::accumulate(b.begin(),b.end(),2),
  };
#else
  const container_t ints{10,20};
#endif  
  return std::accumulate(ints.begin(),ints.end(),100);
}
---------




--
View this message in context: http://clang-developers.42468.n3.nabble.com/missing-optimization-opportunity-for-const-std-vector-compared-to-std-array-tp4034587p4039709.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list