What are the most F.A.Q. on this forum?

Pages: 12345
Thank you for your time!

I am actually trying to keep this as simple as possible. Anything beyond belongs in an Article. (And some of the FAQs I expect will simply be to point to an existing article.)

testing
I am testing all code with GCC 4.3 and GCC 4.6, which are all I have available ATM (as my PC is currently being modified, and I am working on the minimal setup I put on my wife's and kid's PCs). If anyone can validate the code using other compilers that would be great. (Particularly if using MSVC++, the Intel compiler, Comeau, Sun CC, and anything else common for specific systems.)

notes

"As for for C" - fixed.

XML - that is above and beyond. If the user really wants to get into parsing XML himself, he'll find better than the FAQ. If you are interested enough, write an Article and I'll update the FAQ to have a pointer to it.

"hang in" is not missing a "there"; it is an idiom by itself. If unclear, I can change it to read something else.

memory stack vs heap, etc: No, that is beyond the topic at hand.

pointer arithmetic: It is hinted at, but again it is beyond the purposes of this particular FAQ answer.

std::string may contain '\0': I did not think it needed mentioning, but I could be wrong. What does everyone else say?

string literals in memory: It is handled in passing when reading through the c-strings subsection. (Wow, I only just finished that section earlier. Did you see the final version?)

trim use examples: I have no plans to add examples of how to use the functions. At least, I should hope that anyone reading the FAQ knows how to (declare or define and) call a function. I also make frequent note among the code snippets about a (yet to be written) FAQ about incorporating code snippets and headers and multiple files, etc. into one's own code.

The switch on string page needs a rewrite. It is a fairly frequently asked question, so there it is. I feel no need to justify its existence too much. It is useful, though, particularly when handling a predefined collection of inputs, which is common.

The ci-compare page is also unfinished. I need to do a bit more research than I had initially thought, so what you see there is just kind of keeping the spot warm. ;-)

My life is not currently very conducive to spending large amounts of consecutive time on this... what I get are little 10, 30, or 40 minute chunks punctuated by random other things going on. It is very hard to keep my stack from blowing every time I have to move.

Anyway, I'm off to buy my kid a birthday cake right now... (Lemon, yum!) I'll be back later after the (short) festivities (because we're all sick as dogs).
Thanks for doing this, happy birthday to your kid and get well soon, then :)
Updated:

http://cplusplus.com/faq/sequences/strings/c-strings-and-pointers
http://cplusplus.com/faq/intro/#oop OOP
http://cplusplus.com/faq/intro/#generics templates
http://cplusplus.com/faq/intro/#visual Visual C++
http://cplusplus.com/faq/sequences/arrays/sizeof-array/

I have avoided size_t SizeOfArray( T (&)[ N ] ) and size_t SizeOfArray( T (const &)[ N ] ), since some compilers choke on those versions. The latter would be nice because it would get a const reference, but a reference to an array of const is about the same, right?
Last edited on
I'm having issues with sizeof-array (template version)
1
2
3
4
5
int main(){
  int ii[42];
  float ff[size(ii)];
  std::cout << size(ff) << std::endl;
}
g++ 4.6.2
4: error: no matching function for call to ‘size(float [(((long unsigned int)<anonymous>) + 1)])’
note: candidate is:
  template<class T, long unsigned int S> size_t size(const T (&)[S])
The error occurs when I try to get the size, or typeid of the second array.
However sizeof gives the expected result.
Also ¿why did it 'change' the template type?

T (const &)[ N ] ¿what is that?
ne555 wrote:
I can't make my [I should have known someone would try something extra-weird] code work with your function
Yes, because variable-length arrays are not allowed in C++, in part for these reasons. GCC in particular chokes on what you have tried to do.

If you do use VLAs, why do you need to recur to SizeOfArray()? Just use the same value you did when creating the array.

ne555 wrote:
T (const &)[ N ] ¿what is that?

It asks for an unnamed const reference to the array. GCC chokes on that.

Que te guste.

[edit] I added your input on http://cplusplus.com/faq/sequences/arrays/sizeof-array/#cpp-vla Thanks!
Last edited on
Duoas wrote:
T (const &)[ N ] ¿what is that?
It asks for an unnamed const reference to the array. GCC chokes on that.

Not surprisingly, since it's invalid C++.
I forgot -pedantic
But I don't understand why it is a VLA
the compiler will optimize that function out of existence and just plug the actual length of the array in your code where you call it.
1
2
3
static inline const unsigned long int foo() /*throw()*/{ //keywords, xP
  return 42;
}
doesn't work either.


const reference
That would be const T (&foo)
If we say
1
2
3
typedef int array[42];
const array (&foo); //a constant reference to an array of 42 elements
const int (&foo)[42]; //if you prefer. Except here, the other parenthesis are free 

T (const &) [N]¿what are you protecting here? AFAIK you can't rebind a reference, and your type is exposed.


Aprecio la intención, pero no sé que quisiste decir.
Buenas noches.
It is standard (albeit, very weird) syntax.

const T (&)[ N ] is a reference to an array of const T.
T (const &)[ N ] is a const reference to an array of T.

AFAIU.

Ja, es un idioma Mexicano... Es decir, espero que te satisfaga.
Buenas noches. :-)
It is standard (albeit, very weird) syntax.

No.

If const references could exist, the syntax would have been T (&const)[ N ] (similar to the actually existing T (* const)[ N ] ). But (const &) just makes no sense.
Ah, well, then the FAQ has it right, and I'm glad I didn't use it.

Update: http://cplusplus.com/faq/intro/#getting-started

[edit] Good grief! Google is already picking up the new FAQs. I'm not even close to finishing writing them! No pressure. [/edit]
Last edited on
Sorry, I'm using Chrome and I visited the FAQ.

I've done tests on my website and I have found that as soon as I visit a web page in Chrome, it appears in Google search's search results.
Last edited on
Big update.
http://cplusplus.com/faq/sequences/

There are a couple of things I would particularly like reviewed:

- The example in Iterators is, I think, pretty weak. Does anyone have a better example?

- Some effort was made to keep the code thin, so that you don't have to scroll the window to read the text when using a normal window. This lead to a little bit of funky formatting...

- Conceptual progression. Does the page make sense? Do the graphics work?

- I accidentally made the graphics in big-endian, instead of little-endian. Should I take the time to change that?

Thanks again for your support so far!
Last edited on
I like that the example is in big-endian. It may trigger curiosity about endianness (thanks Disch)
[rant]
Designing an iterator class is actually rather difficult, so some third-party libraries lack them.
¿really? (there is even a pattern for that)
¿how do you iterate over such containers?
To make them work with stl algorithms you just need to implement an interface that consists in operators and iterator_traits (thanks flclempire)

Don't take this too seriously. I didn't played with complex structures, and design it is not something that I'm good at.[/rant]

Dunno about the example. If you want print( v.rbegin(), v.rend() ); just to show that the behaviour is in the iterator. (we can choose different ways for traverse the container)

I think that c++0b containers can handle anything 'movable', so you could make one for streams.

If the elements really were not stored in relative order, it would take a very expensive linear search to find an element in the container, particularly when the key you are searching for is not in the container.
well, there is hashing...


Completely off-topic: I always misspell your name, xP
Edit: I had misspellled misspell.
Last edited on
The std::deque is something of a hybrid structure, where the tuples contain small arrays holding only a part of the whole sequence. Use it when you need quick element lookup and also fast element insert and delete.


I would through a plug in there about random access. Actually, perhaps this should be mentioned for the first array example. I'm still reading the article but it seems difficult to break down STL containers without covering iterator categories.
The INI file example seems like a lot to digest at once. It's cool and all but if it's just demonstrating a set or map, how about doing the old how many times each word is used in a file program?

Other than that nit-pick, this is my favorite page I've reviewed so far. I love the array images!
Last edited on
iterator types:
Very good point. I will add discussion of it in the subsection on iterators.

ini file:
Yes, I think it is a bit also, but the "how many times each word is used" thing is a common homework problem. Albatross is helping on the FAQs, and I just sent her this same information:
I wrote:
Oh, also, I have an idea to classify certain parts of the FAQ between two different methodologies. For things like "how do I sort" it is really just a "how-to". But for things like "how do I make my bubble-sort work?" ("sort stuff myself?") it should not give complete code but rather spend some time detailing exactly how the major sort algorithms work, and some of the structures necessary to that end.

I'm planning to write a section on linked lists, probably sooner than later, that fits this second methodology. It will go through the basics, much like a professor would, but it will also require the reader to do his own homework to build a complete, functioning linked list. Sections like "how do I insert a node" will focus on hints, or directing the user to the correct way of thinking about it, rather than just giving an answer in code.

I really don't want the FAQ to be useful for canned homework responses, but rather to help understand the question better.

I'm glad the array images work! Thanks!
I really don't want the FAQ to be useful for canned homework responses, but rather to help understand the question better.


I think I've said it before, I wouldn't be so concerned. You know the whole rest of the internet is in the same place where they found this site... If they want an answer, they'll find it. Some people actually learn even when presented with solutions.

Cater to those who actually want to learn, as those are the ones going places. A little noise in the line isn't going to hurt anybody.
Last edited on
I prefer a superior answer over a canned response that teaches next to nothing.
+1, I think that if they want to learn they should not be presented with direct code solutions.
closed account (3hM2Nwbp)
I just read a little snip of comparing strings (case insensitive).

You might consider recommending boost::iequals.

1
2
3
4
5
6
7
8
9
10
#include <boost/algorithm/string.hpp>
#include <iostream> // *edit - It'd help if this was included, eh?

int main(void)
{
  std::cout << boost::iequals("APPLE", "apple") ? "true" : "false" << std::endl;
  std::cout << boost::iequals("orange", "ORAnGE") ? "true" : "false" << std::endl;
  std::cout << boost::iequals("apple", "orange") ? "true" : "false" << std::endl;
  return 0;
}

true
true
false
Last edited on
Pages: 12345