Skip to content

Commit

Permalink
Require TSource to be a Range (aka Container).
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin1 committed May 2, 2015
1 parent fc09567 commit 31686ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
23 changes: 13 additions & 10 deletions src/cinq_enumerable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ namespace cinq
* @param source the source container which
* provides the data cinq operates on
*/
enumerable(){
is_data_copied=false;

}

enumerable(TSource& source) // requires Container<TSource>()
enumerable(TSource& source) requires Range<TSource>()
{
is_data_copied = false;
begin = source.cbegin();
end = source.cend();
}

enumerable(TSource&& source) // requires Container<TSource>()
enumerable(TSource&& source) requires Range<TSource>()
{
is_data_copied = false;
begin = source.cbegin();
end = source.cend();
}


private:

enumerable()
{
is_data_copied=false;
}

public:

/**
* @brief Filters a sequence of values based on a predicate.
* Each element's index may be used in the logic of the predicate function.
Expand Down Expand Up @@ -920,10 +924,9 @@ namespace cinq
* @return constructs a type enumerable from the container
*/
template <typename T>
//requires Container<T>()
requires Range<T>()
auto from(T& source)
{
//enumerable<decltype(source.cbegin())> e(source);
enumerable<T> e(source);
return e;
}
Expand Down
10 changes: 9 additions & 1 deletion src/cinq_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ vector<test> make_tests()
return (result == answer);
}));

tests.push_back(test("where() with std::string", []
{
string s = "C++ INtegrated Query";
auto result = cinq::from(s)
.where([](auto& x) { return 'A' < x && x < 'Z'; })
.to_vector();
return (result == vector<char>({ 'C', 'I', 'N', 'Q' }));
}));

tests.push_back(test("where() with index std::vector", []
{
std::vector<int> my_vector { 0, 1, 2, 3, 4 };
Expand All @@ -92,7 +101,6 @@ vector<test> make_tests()
return (result == answer);
}));


tests.push_back(test("where() with index std::list", []
{
std::list<int> my_list { 0, 1, 2, 3, 4 };
Expand Down
2 changes: 0 additions & 2 deletions src/custom_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

using namespace origin;

//TODO:Container concept

template<typename _Iter>
concept bool Sortable()
{
Expand Down

0 comments on commit 31686ce

Please sign in to comment.