enow.com Web Search

Search results

  1. Results from the WOW.Com Content Network
  2. c++ - Read file into vector<byte> - Code Review Stack Exchange

    codereview.stackexchange.com/questions/222021

    \$\begingroup\$ Creating byte data[length]; then creating a vector forces a copy. Why not make data a vector and simply return it. Then the compiler can do lots of optimization and build the vector directly at the destination so removing the need for a copy. \$\endgroup\$ –

  3. Implement Own Vector Class in C++ - Code Review Stack Exchange

    codereview.stackexchange.com/questions/221707/implement-own-vector-class-in-c

    10. I am preparing for an interview and came to know about this question: implement a vector class in C++. I thought of how I would write it an interview and included the code below. The things I know I did not cover already are: 1) No use of templates for different data types 2) No use of iterators for iterating.

  4. C++ Vector with templates - Code Review Stack Exchange

    codereview.stackexchange.com/questions/204879/c-vector-with-templates

    I am learning about templates in C++ so I decided to implement an N-dimensional vector. The code seems to work fine, but there are a few things that I am unsure about. To stop GetW() being called on a 3-dimensional vector, I used std::enable_if .

  5. c++ - Vector-transposing function - Code Review Stack Exchange

    codereview.stackexchange.com/questions/214971/vector-transposing-function

    I profiled a library I'm writing that uses vector transposes and found that I am spending a good bit of time doing the following transpose. I am using a std::vector of std::vector&lt;double&gt;s to

  6. c++ - contains() algorithm for std::vector - Code Review Stack...

    codereview.stackexchange.com/questions/59997/contains-algorithm-for-stdvector

    Another obvious possibility would be to continue to store the data in a vector, but keep the vector sorted so you can do the search with std::binary_search. Right now this is O(N). Using std::set or a sorted vector with std::binary_search will reduce that to O(log N).

  7. c++ - Basic iterator supporting vector implementation - Code...

    codereview.stackexchange.com/questions/202157/basic-iterator-supporting-vector...

    The implementation of an iterator is based on the "Iterator Concept". There are actually five types of iterator in C++. But since you are using vector as your example implementation we should consider the "Random Access Iterator Concept". To qualify as a random access iterator you have to uphold a specific contract.

  8. c++ - Removing by indices several elements from a vector - Code...

    codereview.stackexchange.com/questions/206686

    An easy way to do it would be to start with the last element of toRemove and remove them sequentially. However, that would require copying elements at the end of the vector several times which is slow when the vector is large. Here is an alternative using the erase-remove idiom: #include <iostream>. #include <vector>. #include <string>.

  9. c++ - Longest string in a vector - Code Review Stack Exchange

    codereview.stackexchange.com/questions/71877/longest-string-in-a-vector-two...

    The first version of the algorithm uses a traditional C++03-era for loop with iterators. The only modern element is the auto used to deduce an std::vector<std::string>::iterator. The second loop uses a C++11 range-based for loop whose syntax is close to the one used in Java.

  10. c++ - Filter out elements from std::vector - Code Review Stack...

    codereview.stackexchange.com/questions/175713

    I have ended up with the following code in order to filter out some bad elements from a std::vector: #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; typedef struct my...

  11. c++ - Multiply vector elements by a scalar value using STL and...

    codereview.stackexchange.com/questions/77546/multiply-vector-elements-by-a...

    typedef std::vector <T>::size_type size_type ; for (size_type i = 0; i < A.size (); ++i) C++11 has expanded the functionality of the using keyword. So instead of a typedef, you could also do: using size_type = decltype (A.size ()) ; Update: The reason you want to use compatible types is because overflowing a signed number is undefined behavior ...