1,247 Posted Topics
Re: Use [B]boost::sregex_iterator[/B], perhaps? [url]http://www.boost.org/doc/libs/1_47_0/libs/regex/doc/html/boost_regex/ref/regex_iterator.html[/url] (There is an example at the end of the page.) | |
Re: > The idea of policy based class design is very attractive, > yet it is not so popular in the real world. I think it is widely used in the real world; the idea of separating policy from infrastructure is fairly old. Goes under several names - strategy pattern, policy … | |
Re: [CODE]template < typename ITERATOR, typename T > void iota( ITERATOR begin, ITERATOR end, T value ) ;[/CODE] is part of (SGI) STL; it is not part of the standard C++ library. Unless you are using SGI STL (or one of its derivatives), it is likely that this function is not … | |
Re: Make the code const-correct. [url]http://www.parashift.com/c++-faq-lite/const-correctness.html[/url] [CODE]template <class Entry> class HashTable { public: HashTable(); //constructor Key hash_function( [COLOR="Red"]const[/COLOR] Entry &x ) [COLOR="Red"]const[/COLOR] ; void insert( [COLOR="Red"]const[/COLOR] Entry &k ); std::vector<list<Key>> my_vec[97]; }; // also in the definitions [/CODE] | |
Re: The number of entries at each level in a binary heap is a power of two; 1, 2, 4, 8, ...and so on ( 2^N starting with N==0 ). So you need to put a new line to start the next level after 1, 3, 7, 15 and so on. … | |
Re: In most cases where typelists were used in old C++ (for example in [B]tuple<>[/B]) , we do not need them any more - variadic templates would do the job better, and more efficiently too. As such, IMHO, libraries like Boost MPL would be rarely used; most of the verbose and … | |
Re: Looks good to me. Test it out to make sure it's working. With variadic templates (using the earlier 'indexof'): [CODE]template< typename T > struct unique ; template<> struct unique< typelist<> > { typedef typelist<> type ; } ; template< typename FIRST, typename ...REST > struct unique< typelist<FIRST,REST...> > { typedef … | |
Re: You might first want to learn using a game programming library; for instance Allegro. [url]http://alleg.sourceforge.net/[/url] And then learn to use a library for 3D graphics; for instance OpenGL. Ideally, post your questions on boards that specializes in game programming; for instance GameDev [url]http://www.gamedev.net/index[/url] | |
Re: The absence of variadic templates is the fundamental problem with Microsoft C++. It surfaces in several different places posing as different problems. This is (in effect) what the IS says: [CODE]template< typename... TYPES > tuple<TYPES...> std::make_tuple( TYPES&&... args ) ; returns std::tuple<TYPES...>( std::forward<TYPES...>(args...) ) ; with std::reference_wrapper<T> unwrapped to T&[/CODE] … | |
Re: This is usually a result of catastrophic backtracking. [url]http://www.regular-expressions.info/catastrophic.html[/url] | |
Re: See: [url]http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/[/url] | |
Re: Get rid of this: [CODE]Aligned16Vector::Aligned16Vector() { [COLOR="Red"]vector<T,Allocator16<T>>::vector();[/COLOR] // why? // what is the purpose of constructing this anonymous object, // which is immediately destroyed thereafter? }[/CODE] And as already mentioned, this: [ICODE]myVector.~Aligned16Vector();[/ICODE] and things would work out fine. > The Allocate/Delete calls do add up just the order is a … | |
Re: To read a line of text, use [B]std::getline()[/B] [url]http://www.cplusplus.com/reference/string/getline/[/url] To do something with every non blank line in the text file: [CODE]std::string line ; while( std::getline( in_file, line ) && !line.empty() ) { // do something with line }[/CODE] To parse a line that has been read, use a [B]std::istringstream[/B]. … | |
Re: [CODE]void HighLow( vector<SurveyInfo> List [COLOR="Red"]/*[K]*/[/COLOR] ) // typo? { [COLOR="Red"]if( List.empty() ) return ;[/COLOR] // just to be safe int K; int Low = List[0]; int High = List[0]; for(K = 0 ; K < [COLOR="Red"]/*6*/ List.size()[/COLOR] ; K++) // where did 6 come from? if(List[K] < Low) Low = … | |
Re: In general, to navigate through object-oriented types, use a dynamic down-cast or a dynamic cross cast. Languages like C++, java or eiffel have limited support for object-oriented programming (they are very unlike smalltalk or self). For example, a static member function is not polymorphic at run time; virtual function signatures … | |
Re: [B]volatile[/B] variables; so you would be measuring the total time for arithmetic operations as well as loads and stores from/to (cache) memory. Is that your intent? [CODE]void foobar() { static volatile float a = 1.5; static volatile float b = 1.6; a *= b ; // multiplication operation // assembly … | |
Re: Test immediately after (not before) reading a line. [CODE]while( [COLOR="Green"]/*! myfile.eof()*/[/COLOR] [COLOR="Red"]getline(myfile,buffer)[/COLOR] ) { [COLOR="Green"]/*getline(myfile,buffer);*/[/COLOR] // ...[/CODE] | |
Re: Create two index files, perhaps? [B]keywords.idx[/B] for keywords with each line containing: [B]keyword path, [ path... ][/B] [I]jade[/I] aaron_rogers.txt brett_favre.txt calvin_johnson.txt [I]amethyst[/I] jahvid_best.txt mathew_stafford.txt [I]urgent[/I] tom_brady.txt tony_romo.txt // etc [B]ordernumbers.idx[/B] with each line containing: [B]ordernumber path[/B] 10237 aaron_rogers.txt 11384 brett_favre.txt etc. On program startup read keywords.idx into a [B]std::map< std::string, … | |
Re: [CODE]#include <limits> #include <iostream> int main() { std::cout << "does the type double have a representation for positive infinity? " << std::boolalpha << std::numeric_limits<double>::has_infinity << '\n' ; // if the answer was true, representation of positive infinity. const double infinity = std::numeric_limits<double>::infinity() ; // maximum possible [B]finite[/B] value. const double … | |
Re: It appears that a. There are going to be a very large number of [B]DataStruct[/B] and [B]Action[/B] objects (since the memory footprint of [B]DataStruct[/B] is quite small). b. [B]DataStruct[/B] objects are added, but never removed (since the key is based on the size of the map). In that case, using … | |
Re: One way is for the binary function to also provides a metafunction rebind a la allocators. [CODE]template< typename T, typename U > struct my_fun // TODO: std::enable_if for std::is_integral { bool operator() ( const T& a, const U& b ) const { return b != 0 && a%b == 0 … | |
Re: Shouldn't you be using a virtual function instead of dispatching on type looked up at run-time? The lifetime of the object returned by [B]typeid()[/B] is guaranteed by the standard, so the following would work: [CODE]void foo( base& b ) { derived_A& a = dynamic_cast<derived_A&>(b) ; /* ... */ } void … | |
Re: Use Boost.Program_options, perhaps? [url]http://www.boost.org/doc/libs/1_47_0/doc/html/program_options/tutorial.html[/url] | |
Re: > can I use this DLL now without recompiling my C code No. The ABIs (an ABI specifies things like data size, alignment, calling convention, binary formats of programs, object files and libraries, name decoration, exception propagation and so on) are different. | |
Re: > keep track of the number of times that a given combination of words occurs in a file Is a recursively nested map of unknown (at compile-time) depth the best data structure for this? Use a variant of a trie (which also stores the count in each node) perhaps? [url]http://en.wikipedia.org/wiki/Trie[/url] … | |
Re: See Chapter 6: 'Insulation. Specific techniques for reducing compile-time dependencies' in 'Large-Scale C++ Software Design' by John Lakos [url]http://www.amazon.com/Large-Scale-Software-Design-John-Lakos/dp/product-description/0201633620[/url] Also presented as Items 26 to 30 of 'Exceptional C++' by Herb Sutter. [url]http://www.pearsoned.co.uk/bookshop/detail.asp?item=171019[/url] | |
Re: [CODE]struct tm* logTime ; // ***[/CODE] You haven't got a struct tm; all you have is a pointer. > How do I need to go about the actual conversion of that format into the struct? Use a look-up table, perhaps? [CODE]const wchar_t* const month_names[12] = { L"Jan", L"Feb" /* , … | |
Re: > I know how to send data in one struct and receive it on the other side, because there is constant size of structure. Assuming that you are not converting to/from a common network data representation of the struct, this will work only if the POD struct involved has the … | |
Re: > Is it really hard to find someone who know how to make a good use of stl No. AFAIK, STL (and in many cases boost) have been mainstream for some years. > ... Like the way modern c++ design did? Yes. 'Modern C++ Design' went beyond just making good … | |
Re: Use [B]std::initializer_list<>[/B] [url]http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=424[/url] [CODE]#include <initializer_list> template< typename T > void foo( std::initializer_list< std::initializer_list<T> > a ) { // ... } int main() { foo( { { 1, 2, 3 }, { 4, 5, 6 } } ) ; }[/CODE] | |
Re: [CODE]template< typename T > struct Node { [COLOR="Green"]/*struct*/[/COLOR] Node( T data ) { this->data = data; previous = NULL; next = NULL; } T data; [COLOR="Green"]/*struct*/[/COLOR] Node *previous; // keyword struct is superfluous here [COLOR="Green"]/*struct*/[/COLOR] Node *next; } [COLOR="Green"]/*NODE*/[/COLOR] ; template< typename T > class LinkedList { protected: [COLOR="Green"]/*NODE*/[/COLOR] [COLOR="Red"]Node<T>[/COLOR]* … | |
Re: Alternatively, use a pure object-oriented interface. [CODE]////////// header my_class.h //////////////////////////// // include guard #include <memory> struct my_class { static std::shared_ptr<my_class> create(int,int) ; virtual ~my_class() ; virtual int my_fun( int a, int b ) = 0 ; // virtual ... = 0 ; // virtual ... = 0 ; };[/CODE] [CODE]////////// … | |
Re: > Is there a specific location where I have to put my input.txt file? Either place [B]input.txt[/B] in the working directory of your program. Or use a complete path like [B]"C:\\some_dir\\etc\\etc\\input.txt"[/B] instead of a relative patch. | |
Re: If the file is small enough, read it into a [B]std::vector<unsigned char>[/B] and use the container's [B]reverse_iterator[/B]. If it is big, either read it in chunk by chunk or memory map the file [url]http://www.freebsd.org/cgi/man.cgi?query=mmap[/url] | |
Re: [CODE] float num[3][3]; std::cout << "Enter 9 numbers: "; for (int i = 0; i < 3; ++i ) for( int j = 0 ; j < 3 ; ++j ) std::cin >> num[i][j]; for (int i = 0; i < 3; ++i ) { for( int j = 0 … | |
Re: > I want to ether copy it to another location [CODE]#include <fstream> int main() { std::ifstream fin( "myfile.dat", ios_base::in|std::ios_base::binary ) ; std::ofstream fout( "myfile.cpy", ios_base::out|std::ios_base::binary ) ; fout << fin.rdbuf() ; }[/CODE] > or (more likely) send it through zlib's deflate. Simplest if you use a C++ wrapper over zlib. … | |
Re: > is asio as robust as ACE? Probably not. ACE has been in wide use for a much longer time. > the performance between asio and ACE ACE is heavyweight in terms of memory footprint; asio is not. In terms of speed, it shouldn't make a difference: you can execute … | |
Re: an alternative is to use the ctype<> facet. the advantages are a. also works with c++ strings b. locales other than the default locale are supported (behaviour is unaffected by the LC_CTYPE category of the current c locale). 3. will not fail if a wide-character code encountered does not correspond … | |
Re: > I need to make a function that returns an array. There is no way to return an array from a function (in either C or C++). You can return a pointer to the first element of a dynamically allocated memory (which is messy). You could return a reference to … | |
Re: > wouldn't it make sense to change them to by default be explicit? Yes, it would. If it was meditated on right at the outset, I guess the keyword would have been [B]implicit[/B] - constructors would have been explicit by default. However, an important consideration during standardization is that when … | |
Re: > i thought that template <typename T> is for fundamental types and template <class T> is for user defined types. > ... what is the main difference between them? There is no difference. | |
Re: it does build on FreeBSD. and therefore should build on Solaris. here is an extract of the make output. as you can see from it, the Makefile does not have anything special. are you using the wrong Makefile? or a different version of the library? [CODE]root@/usr/ports/net-mgmt/snmp++:#make => snmp++v3.2.22.tar.gz doesn't seem … | |
Re: Your class should be something like this: [CODE]class phone { public: // The type member is an enumeration of HOME, OFFICE, FAX, CELL, and PAGER enum phone_type_t = { HOME, OFFICE, FAX, CELL, PAGER } ; // *** added phone(); //phone(int coCode, int arCode, int phNumber); // optional // A … | |
Re: > Can I add up the memory values of A through F and then add them up > for whatever variant on them is passed and see if those two values are equal? No. (why?) One way is to use the [B]==[/B] operator of [B]std::set<>[/B] [CODE]std::string str = "vjjjJGJGJGJgjjVHhACDBFEfhyffhyfhyfhyf" ; … | |
Re: > I need to know how to make it pull just the information that I need to compare. For input, use [B]std::ifstream[/B] To read line by line from the stream, use [B]std::getline[/B] To extract the information from the line, use [B]std::istringstream[/B] For example, [CODE] std::ifstream old_file( "oldfile.dat" ) ; std::string … | |
Re: For each class, you need to have a header file [B]x.h[/B] and an implementation file [B]x.cpp[/B]. Include the header file in order to use the class. For example: [CODE]//////////// duties.h ///////////////// #ifndef DUTIES_H_INCLUDED_ #define DUTIES_H_INCLUDED_ #include <string> class Duties { public: static void submitChangeDutyRequests( const string& ) ; }; #endif … | |
Re: > how are they referring to references being safe? Who are 'they'? I think they are trying to say: [CODE]void foo( A& a ) ; // we can assume that a refers to a valid object // unless code that results in undefined behaviour has been executed // prior to … | |
Re: A good starting point is Jack Crenshaw's "Let's Build a Compiler!" [url]http://www.penguin.cz/~radek/book/lets_build_a_compiler/[/url] | |
Re: Template instantiation is done at compile-time; no there is no run-time overhead for instantiating a template. > but I am not sure how implicit function invokation works. > I don`t think compiler will create a different function for evey datatype available > (since there can be many different data-types in … |
The End.