|
-
June 13th, 2003, 02:29 AM
#46
what happened to the
obfuscated "Hello world!" application
??!?!??!?!?!?1
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames
-
June 13th, 2003, 03:38 AM
#47
Code:
#include <iostream>
#include <list>
#include <boost/any.hpp>
#include <algorithm>
using namespace std;
typedef list<boost::any> lany;
template <typename T>void Larry(T t){}
template <>void Larry(int t){if(t) cout<<"H"; else cout<<"d";}
template <>void Larry(float t){if(!t) cout<<"e"; else cout<<"l";}
template <>void Larry(bool t){if(t) cout<<"o"; else cout<<" ";}
template <>void Larry(double t){if(t) cout<<"w"; else cout<<"r";}
template <>void Larry(char t){if(t) cout<<"!"; else cout<<"\n";}
void Jimmy( const boost::any & Any)
{
try{Larry(boost::any_cast<int> (Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<float> (Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<bool> (Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<double>(Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<char> (Any));} catch(boost::bad_any_cast&){}
}
int main()
{
lany Lany;
Lany.push_back(boost::any(1));
Lany.push_back(boost::any(0.0f));
Lany.push_back(boost::any(1.0f));
Lany.push_back(boost::any(1.0f));
Lany.push_back(boost::any(true));
Lany.push_back(boost::any(false));
Lany.push_back(boost::any(1.0));
Lany.push_back(boost::any(true));
Lany.push_back(boost::any(0.0));
Lany.push_back(boost::any(1.0f));
Lany.push_back(boost::any(0));
Lany.push_back(boost::any('x'));
Lany.push_back(boost::any('\0'));
for_each(Lany.begin(), Lany.end(), Jimmy);
return 0;
}
-
June 13th, 2003, 05:06 AM
#48
Originally posted by galathaea
Hmm, I think I still don't get it.....
well you got the purple part which other part are you not getting...
-
June 13th, 2003, 09:06 AM
#49
Originally posted by Gabriel Fleseriu
Code:
#include <iostream>
#include <list>
#include <boost/any.hpp>
#include <algorithm>
using namespace std;
typedef list<boost::any> lany;
template <typename T>void Larry(T t){}
template <>void Larry(int t){if(t) cout<<"H"; else cout<<"d";}
template <>void Larry(float t){if(!t) cout<<"e"; else cout<<"l";}
template <>void Larry(bool t){if(t) cout<<"o"; else cout<<" ";}
template <>void Larry(double t){if(t) cout<<"w"; else cout<<"r";}
template <>void Larry(char t){if(t) cout<<"!"; else cout<<"\n";}
void Jimmy( const boost::any & Any)
{
try{Larry(boost::any_cast<int> (Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<float> (Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<bool> (Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<double>(Any));} catch(boost::bad_any_cast&){}
try{Larry(boost::any_cast<char> (Any));} catch(boost::bad_any_cast&){}
}
int main()
{
lany Lany;
Lany.push_back(boost::any(1));
Lany.push_back(boost::any(0.0f));
Lany.push_back(boost::any(1.0f));
Lany.push_back(boost::any(1.0f));
Lany.push_back(boost::any(true));
Lany.push_back(boost::any(false));
Lany.push_back(boost::any(1.0));
Lany.push_back(boost::any(true));
Lany.push_back(boost::any(0.0));
Lany.push_back(boost::any(1.0f));
Lany.push_back(boost::any(0));
Lany.push_back(boost::any('x'));
Lany.push_back(boost::any('\0'));
for_each(Lany.begin(), Lany.end(), Jimmy);
return 0;
}
Gabriel, what does this program mean ?...ahmm.. what is the include<... .hpp > used for ?
Thank you veru much...
Regards
-
June 13th, 2003, 09:16 AM
#50
Originally posted by hometown
Gabriel, what does this program mean ?...ahmm.. what is the include<... .hpp > used for ?
Thank you veru much...
Regards
As (almost) every program in this thread, this one also prints "Hello world!". I find it rather funny than obfuscated. The extension ".hpp" is a header extension. The boost library (www.boost.org) uses it.
Does this answer your question, or do you want to know how it works?
-
June 13th, 2003, 09:44 AM
#51
Thank you Gabriel,
You mean if I would like to use such a .hpp file I will have to download it from boost ?
But what is that header file used for ?
-
June 13th, 2003, 09:50 AM
#52
Re: Thank you Gabriel,
Originally posted by hometown
You mean if I would like to use such a .hpp file I will have to download it from boost ?
But what is that header file used for ?
If you want to use any of the boost' libraries, then yes, you will have to download them from boost. That doesn't mean that you are not allowed to name your own headers "something.hpp". The extension .hpp is as good as .h -- actually it signals that the header is C++ specific (.c vs. .cpp --> .h vs. .hpp);
<boost/any.hpp> is the header that implements the class boost::any. To make a long story short, this class can hold (nearly) any type of variable -- thus the name. Read the boost documentation if you want to know more.
-
June 13th, 2003, 09:57 AM
#53
Thank you Gabriel very much...
Originally posted by Gabriel Fleseriu
If you want to use any of the boost' libraries, then yes, you will have to download them from boost. That doesn't mean that you are not allowed to name your own headers "something.hpp". The extension .hpp is as good as .h -- actually it signals that the header is C++ specific (.c vs. .cpp --> .h vs. .hpp);
<boost/any.hpp> is the header that implements the class boost::any. To make a long story short, this class can hold (nearly) any type of variable -- thus the name. Read the boost documentation if you want to know more.
-
June 13th, 2003, 03:51 PM
#54
The file extension really doesn't matter, some people do like the hpp, but the standard library has no file extension. You could make up an extension and as long as your compiler knows its a header file it will compile.
-
June 13th, 2003, 07:16 PM
#55
Thank you very much...
Originally posted by mwilliamson
The file extension really doesn't matter, some people do like the hpp, but the standard library has no file extension. You could make up an extension and as long as your compiler knows its a header file it will compile.
I tried making a bunch of files with different extensions, and they all work fine 
Thank you very much...
-
June 16th, 2003, 09:24 PM
#56
Gabriel Fleseriu
quote:
--------------------------------------------------------------------------------
Originally posted by galathaea
Gabriel, your post is nonstandard because it assumes an ANSI character set...
--------------------------------------------------------------------------------
Bingo!
I can't find this part of the standard. What page is this
mentioned on ?
And are you talking about wchar_t /vs char or am I missing
something.
-
June 17th, 2003, 06:42 AM
#57
Originally posted by mdmd
I can't find this part of the standard. What page is this
mentioned on ?
And are you talking about wchar_t /vs char or am I missing
something.
The Standard does not say that the target platform has to have an ASCII character set. For example, some IBM computers use the so called EBCDIC character set, if my memory serves me correctly. If you run my program on such a machine, it printed some bogus string.
-
July 2nd, 2003, 12:40 AM
#58
-
July 2nd, 2003, 07:21 AM
#59
A minimal "Hello, world!".
This should be fairly standard:
Code:
#include <sstream>
#include <algorithm>
#include <iostream>
template <class X> class K
{
std::basic_string<X> b, s;
public:
K(const std::basic_string<X> &z) : b(z)
{
std::for_each(++(s = static_cast<std::ostringstream *>(&(std::ostringstream() << std::endl <<
"!dlrow olleH" << std::ends))->str()).rbegin(), s.rend(), *this);
}
void operator()(std::basic_string<X>::value_type &d) const
{
if(b.find(d) == std::basic_string<std::basic_string<X>::value_type>::npos) std::cout << d;
}
};
int main()
{
K<char> k("abcfgijkmnpqstuvxyz");
return 0;
}
-
July 19th, 2004, 05:00 AM
#60
Something easy to understand:
Code:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
typedef vector<string> StringVector;
typedef StringVector::iterator StringVectorIterator;
typedef ostream_iterator<string> StringOstreamIterator;
int main(int argc, char* argv[])
{
int i;
const int VECTOR_SIZE = 0x05;
char limits[] = {'('-1,'7'};
char mixture[] = {0x1D, 0x27, 0x00, 0x24, 0x24, 0x18, 0x0D, 0x1B, 0x00, 0x15};
StringVector one_word(VECTOR_SIZE);
StringVector another_word(VECTOR_SIZE);
StringVectorIterator start_one_word_it, end_one_word_it;
StringVectorIterator start_another_word_it, end_another_word_it;
StringOstreamIterator out_one_word_it(cout, "");
StringOstreamIterator out_another_word_it(cout, "");
start_one_word_it = one_word.begin();
end_one_word_it = one_word.end();
start_another_word_it = another_word.begin();
end_another_word_it = another_word.end();
for(i =0; i<VECTOR_SIZE; i++)
one_word[i] = mixture[i] + 0x48;
for(; i<VECTOR_SIZE<<1; i++)
another_word[i-VECTOR_SIZE] = mixture[i] + 0x57;
for(i=0; i<limits[0]; i++, next_permutation(start_one_word_it, end_one_word_it));
for(i=0; i<limits[1]; i++, next_permutation(start_another_word_it, end_another_word_it));
copy(start_one_word_it, end_one_word_it, out_one_word_it);
cout << " ";
copy(start_another_word_it, end_another_word_it, out_another_word_it);
cout << "!" << endl ;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|