Skip to main content
deleted 5 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int>vector v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <cassert>?

Good:

I like that you can now use the foreach loop:

std::vector<int>vector v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int>vector v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <cassert>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <cassert>?

Good:

I like that you can now use the foreach loop:

std::vector v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6
deleted 1 character in body
Source Link
jdt
  • 2.5k
  • 6
  • 22

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <assert.h><cassert>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <assert.h>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <cassert>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6
added 307 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <assert.h>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <assert.h>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

With C++17 the compiler should be able to deduce the template type automatically by using the following:

template <typename Iterator>
class ConstVectorSubrange {
public:
    using T = typename Iterator::value_type;
    // ...
}

int main() 
{
    std::vector<int> v{ 1, 2, 3, 4, 5, 6, 7, 8 };
    ConstVectorSubrange range(v.begin() + 2, v.end() - 2);
}

I'm not sure why you have included <iterator> and failed to include <assert.h>?

Good:

I like that you can now use the foreach loop:

std::vector<int> v{ 7, 7, 3, 4, 5, 6, 7, 7, 8, 9 };
ConstVectorSubrange vsr(v.begin() + 4, v.end());
for (int i : vsr)
    std::cout << i << "\n";

And all the cool stuff from <algorithm>

std::cout << std::count(vsr.begin(), vsr.end(), 7) << "\n";

Ideas:

It would be pretty cool if you could include a step or stride to have a slice of the vector. Something like this:

std::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::size_t step = 2;
ConstVectorSubrange r(v.begin() + 1, v.end(), step);
for (int i : r)
    std::cout << i << "\n";
// expected results 2, 4, 6
added 143 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading
edited body
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading