About 144,000 results
Open links in new tab
  1. Efficient way to return a std::vector in c++ - Stack Overflow

    std::vector<X> f(); That is, return by value. With C++11, std::vector has move-semantics, which means the local vector declared in your function will be moved on return and in some cases …

  2. Return vector from a function C++ - Stack Overflow

    I am trying to return a vector with the values in the reverse order (e.g, I enter a vector with 0,1,2,3,4 and the function return a vector with 4,3,2,1,0). The compiler says: Segmentation …

  3. c++ - Why is it OK to return a 'vector' from a function ... - Stack ...

    Pre C++11: The function will not return the local variable, but rather a copy of it. Your compiler might however perform an optimization where no actual copy action is made. See this …

  4. In C++, is it still bad practice to return a vector from a function?

    However, allocating one huge vector of 8GB is definitly more expensive than allocating one vector of 32MB, so reusing the vector's capacity provides performance gains. From numIter = 512 …

  5. c++ - How to return a vector from a function - Stack Overflow

    Sep 15, 2013 · Returning a vector by value makes a copy, which is inefficient for large vectors. Make it return a pointer to a vector allocated by new instead. Or pass to the function a vector …

  6. What is the best way to return a vector from a function in c++

    Use the first if you want a vector containing just those strings; use the second if you want to be able to append those strings to an existing vector. If you want the semantics of the first …

  7. c++ - vector in function - how to do return - Stack Overflow

    Aug 8, 2012 · Well, you are trying to return a vector as strings. This won't work because they are different types and have no conversion defined from one to the other. Your function has the …

  8. c++ - Returning std::vector with std::move - Stack Overflow

    Instead declare the function to return by value. This way the caller's value will be move constructed by the r-value returned by the function. The returned value will also bind to any …

  9. Returning a c++ std::vector without a copy? - Stack Overflow

    +1 For the second form being the usual way to do this. The problem with the first example std::vector<A>& MyFunc(); is that the vector has to be allocated somewhere - MyFunc can't …

  10. vector - returning c++ iterators - Stack Overflow

    May 9, 2012 · Return vector::end(), throw an exception, or return something other than a plain iterator. Better yet, don't implement your own Find function. That is what the <algorithm> …

Refresh