I want to remove an item from the result of a LINQ query before using it to databind. What is the proper way to do this?
The foreach in my illustration is the topic of my question. Illustration:
var obj =
(from a in dc.Activities
where a.Referrer != null
&& a.Referrer.Trim().Length > 12
&& a.Session.IP.NumProblems == 0...
This may seem frivolous to some of you, but which of the following 2 methods of iteration over a STL container is better? Why?
class Elem;
typedef vector<Elem> ElemVec;
ElemVec elemVec;
// Method 0
for (ElemVec::iterator i = elemVec.begin(); i != elemVec.end(); ++i)
{
Elem& e = *i;
// Do something
}
// Method 1
for (int i = 0;...
What is the performance difference between using an iterator to loop through an STL map, versus a vector? I'd like to use the map key for insertion, deletion, and some accesses, but I also need to do regular accesses to every element in the map.
...
I want to know everything about the yield statement, in an easy to understand form.
I have read about the yield statement and its ease when implementing the iterator pattern. However, most of it is very dry. I would like to get under the covers and see how Microsoft handles return yield.
Also, when do you use yield break?
...
I have a std::vector with n elements. Now I need to pass a pointer to a vector that has the last n-1 elements to a function.
For example, my vector<int> foo contains (5,2,6,87,251). A function takes vector<int>* and I want to pass it a pointer to (2,6,87,251).
Can I just (safely) take the iterator ++foo.begin(), convert it to a pointer...
I'm writing an agglomerative clustering algorithm in java and having trouble with a remove operation. It seems to always fail when the number of clusters reaches half the initial number.
In the sample code below, clusters is a Collection<Collection<Integer>>.
while(clusters.size() > K){
// determine smallest distance b...
Our coding guidelines say prefer const_iterator, because they are little faster compared to normal iterator. It seems like compiler optimizes the code when you use the const _iterator.
Is it really correct ? If yes, what really happens internally to make const_iterator takes the edge?.
EDIT: I wrote small test to check const_iterator ...
I have a class X, which I provide a snippet of here:
class X {
public:
template <typename Iter>
X(Iter begin, Iter end) : mVec(begin, end) {}
private:
vector<Y> const mVec;
};
I now want to add a new concatenating constructor to this class, something like:
template <typename Iter1, typename Iter2>
X(Iter1 begin1, Ite...
I'm planning to implement a list of Things in C++ where elements might be removed out of order. I don't expect that i'll need any kind of random access (i just need to sweep the list periodically), and the order of items isn't important either.
So I thought of std::list<Thing*> with this->position = insert(lst.end(), thing) should do th...
As an extension to this question Are const_iterators faster?, I have another question on const_iterators. How to remove constness of a const_iterator?
Though iterators are generalised form of pointers but still const_iterator and iterators are two different things. Hence, I believe, I also cannot use const_cast<> to covert from const_i...
Someone here recently brought up the article from Scott Meyers that says:
Prefer iterators over const_iterators (pdf link).
Someone else was commenting that the article is probably outdated. I'm wondering what your opinions are?
Here is mine: One of the main points of the article is that you cannot erase or insert on a const_iterat...
I am working on a merge sort function. I got the sort down - I am trying to get my merge part finished. Assume that I am learning C++, have cursory knowledge of pointers, and don't understand all the rules of std::vector::iterator's (or std::vector's, for that matter).
Assume that num is the size of the original std::vector that have c...
Suppose I've got a method that accepts an array and processes each element in it using Java's built in for-each loop, like this:
public static void myFun(SomeClass[] arr) {
for (SomeClass sc : arr) {
// Stuff is processed here
}
}
This works just fine, but now I want to be able to pass the same method a List<SomeClass>...
I have a std::map declared thusly in a legacy MFC application:
typedef std::map<long, CNutrientInfo> NUTRIENT_INFO_MAP;
typedef NUTRIENT_INFO_MAP::const_iterator NUTRIENT_INFO_ITER;
typedef NUTRIENT_INFO_MAP::value_type NUTRIENT_INFO_PAIR;
static NUTRIENT_INFO_MAP m_NutrientInfoMap;
m_NutrientInfoMap is populated when the app loads by...
I'd like an iterator in C++ that can only iterate over elements of a specific type. In the following example, I want to iterate only on elements that are SubType instances.
vector<Type*> the_vector;
the_vector.push_back(new Type(1));
the_vector.push_back(new SubType(2)); //SubType derives from Type
the_vector.push_back(new Type(3));
t...
In terms of performance, what would work faster? Is there a difference? Is it platform dependent?
//1. Using vector<string>::iterator:
vector<string> vs = GetVector();
for(vector<string>::iterator it = vs.begin(); it != vs.end(); ++it)
{
*it = "Am I faster?";
}
//2. Using size_t index:
for(size_t i = 0; i < vs.size(); ++i)
{
//...
I want to implement a method like this:
public Iterator<File> getFiles(String root) {
// return an Iterator looping through all files in root and all files in sub-directories of roots (recursively)
}
In C#, this can easily be implemented with the yield return keyword. In Java, I suspect I have to end up writing a lot of complicated...
I've been having some trouble with vs2008 SP1 running in debug mode when I try to disable checked iterators. The following program reproduces the problem (a crash in the string destructor):
#define _HAS_ITERATOR_DEBUGGING 0
#include <sstream>
int do_stuff(std::string const& text)
{
std::string::const_iterator i(text.end());
r...
Does anyone know good source where I can find about implementation of SQL iterator/Operator in java and any other languages?
Than you,
-Nimesh
...
I am passed an Iterator and I have to pass it on to another function -- but filtered so that certain elements are skipped (it's a range of pointers, and I want to filter out the NULL pointers).
I googled for "stl filter iterator" to see how to do this, and boost::filter_iterator came up.
That looks nice and I could use it, but could ...