• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 10:24
CET 15:24
KST 23:24
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (October 19-25): Clem triples first in 5.0.175Evil Geniuses - shutting down20ISSL (IntoTheTV x SOOP SC2 League): Premier6Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League92
StarCraft 2
General
Weekly Cups (October 19-25): Clem triples first in 5.0.17 No more SC2 streamers on team liquid? How do you feel about the mass reverts in the 5.0.17 PTR? Evil Geniuses - shutting down REPORT: StarCraft 2: Remastered In Development
Tourneys
ISSL (IntoTheTV x SOOP SC2 League): Premier Stellar Fest TWO the Moon (Dec 16-20) RSL 2026 Offline Finals LCQ Sign-Ups Sparkling Tuna Cup - Weekly Open Tournament 2026 KungFu Cup Announcement
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Simple Questions/Answers [G] How to playtest arcade maps [A] Nemrods 1/4 players
External Content
Mutation # 549 Endless Sparkles The PondCast: SC2 News & Results Mutation # 548 Shining Bright Mutation # 547 Temple Of Terror
Brood War
General
Rollback Netcode in Brood War BW General Discussion SCHNAIL now supports Remastered [Megathread] Daily Funny Videos SC4ALL II Brood War Complete Invited Player Lineup
Tourneys
[Megathread] Daily Proleagues [Women's StarCraft] MonstarZ vs BA 2026-10-30 Star Con San Diego 2026 Small VOD Thread 2.0
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Mobile Legends: Bang Bang Armies of Exigo - YesYes? General RTS Discussion Thread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread R I P Patrick Stewart Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
TeamLiquid Health and Fitness Initiative For 2023 Football (Soccer) Thread MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8196 users

The Big Programming Thread - Page 434

Forum Index > General Forum
Post a Reply
Prev 1 432 433 434 435 436 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2014-01-26 07:27:52
January 26 2014 07:01 GMT
#8661
You told it to print whenever x is true and didn't ever set x to false.

if (x){
System.out.println("Found");
}


When it gets to this line x is true so it prints Found.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Manit0u
Profile Blog Joined August 2004
Poland17865 Posts
Last Edited: 2014-01-26 13:32:43
January 26 2014 13:07 GMT
#8662
On January 26 2014 15:53 Housemd wrote:
Update on Program:

int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30};
Scanner scan = new Scanner (System.in);
boolean x = true;
System.out.print("Please input a number");
int SearchValue = scan.nextInt();
for (int i = 0; i < array.length; i++){
if (x == true){
SearchValue = array [i];
break;
}
}
if (x){
System.out.println("Found");
}
else
{
System.out.println("Not Found");
}
}
}


Works perfectly fine for values that are in the array. For values that are not, it still prints out found. I believe that I have a small syntax error (in the last if-else statement?) but I cannot spot it. I tried to use Chocolate's suggestions of booleans and it looks promising.


Why use for loop here instead of foreach?


Scanner in = new Scanner (System.in);
int SearchValue = in.nextlnt();
int arr[] = { 1, 2, 3, 4, 5 };

System.out.print("Please input a number: ");

for (int n: arr)
{
if (n == SearchValue)
{
System.out.println("Found");
}
else
{
System.out.println("Not found");
}
}
Time is precious. Waste it wisely.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-01-26 13:46:38
January 26 2014 13:46 GMT
#8663
^ isn't this also called enumeration or is it called enumeration only in Objective-C?


for(NSString *aString in [array reverseObjectEnumerator])
{
NSLog(@"Value: %@",aString);
}
mishimaBeef
Profile Blog Joined January 2010
Canada2259 Posts
Last Edited: 2014-01-26 15:03:57
January 26 2014 14:57 GMT
#8664
Does anyone know how to upload data from my PC to Flash memory on my fpga dev board? (de0)

edit: ok i think i have an idea now, to use JTAG UART controller
Dare to live the life you have dreamed for yourself. Go forward and make your dreams come true. - Ralph Waldo Emerson
bangsholt
Profile Joined June 2011
Denmark138 Posts
January 26 2014 15:03 GMT
#8665
On January 26 2014 22:07 Manit0u wrote:
Show nested quote +
On January 26 2014 15:53 Housemd wrote:
Update on Program:

int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30};
Scanner scan = new Scanner (System.in);
boolean x = true;
System.out.print("Please input a number");
int SearchValue = scan.nextInt();
for (int i = 0; i < array.length; i++){
if (x == true){
SearchValue = array [i];
break;
}
}
if (x){
System.out.println("Found");
}
else
{
System.out.println("Not Found");
}
}
}


Works perfectly fine for values that are in the array. For values that are not, it still prints out found. I believe that I have a small syntax error (in the last if-else statement?) but I cannot spot it. I tried to use Chocolate's suggestions of booleans and it looks promising.


Why use for loop here instead of foreach?


Scanner in = new Scanner (System.in);
int SearchValue = in.nextlnt();
int arr[] = { 1, 2, 3, 4, 5 };

System.out.print("Please input a number: ");

for (int n: arr)
{
if (n == SearchValue)
{
System.out.println("Found");
}
else
{
System.out.println("Not found");
}
}


His first post states that he needs to use a for-loop, so that would probably be a good reason ;o)

Also this doesn't satisfy the requirement put forth in the same post, which was that, if the number is found a "Found" shall be printed, otherwise a "Not found" shall be printed after the end of the search.



On January 26 2014 22:46 darkness wrote:
^ isn't this also called enumeration or is it called enumeration only in Objective-C?


for(NSString *aString in [array reverseObjectEnumerator])
{
NSLog(@"Value: %@",aString);
}


No, it's conceptually a for-each loop so it would make the most sense to call it that (Implementation wise it's done using the Iterator interface in Java, the IEnumerable in C# and probably other interfaces in other languages)

And enumeration is something different again ;o)
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
January 26 2014 15:32 GMT
#8666
On January 26 2014 22:46 darkness wrote:
^ isn't this also called enumeration or is it called enumeration only in Objective-C?


for(NSString *aString in [array reverseObjectEnumerator])
{
NSLog(@"Value: %@",aString);
}

Wait, they call that enumeration in Objective-C? Then what do they call actual enumerations, just enum?
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
January 26 2014 17:07 GMT
#8667
On January 27 2014 00:32 Tobberoth wrote:
Show nested quote +
On January 26 2014 22:46 darkness wrote:
^ isn't this also called enumeration or is it called enumeration only in Objective-C?


for(NSString *aString in [array reverseObjectEnumerator])
{
NSLog(@"Value: %@",aString);
}

Wait, they call that enumeration in Objective-C? Then what do they call actual enumerations, just enum?


Well, I dunno. I've just checked those:

http://stackoverflow.com/questions/1314092/how-does-fast-enumeration-looping-work-in-objective-c-ie-for-nsstring-ast
http://www.tutorialspoint.com/objective_c/objective_c_fast_enumeration.htm
Manit0u
Profile Blog Joined August 2004
Poland17865 Posts
Last Edited: 2014-01-26 18:39:00
January 26 2014 18:26 GMT
#8668
On January 27 2014 00:03 bangsholt wrote:
Show nested quote +
On January 26 2014 22:07 Manit0u wrote:
On January 26 2014 15:53 Housemd wrote:
Update on Program:

int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30};
Scanner scan = new Scanner (System.in);
boolean x = true;
System.out.print("Please input a number");
int SearchValue = scan.nextInt();
for (int i = 0; i < array.length; i++){
if (x == true){
SearchValue = array [i];
break;
}
}
if (x){
System.out.println("Found");
}
else
{
System.out.println("Not Found");
}
}
}


Works perfectly fine for values that are in the array. For values that are not, it still prints out found. I believe that I have a small syntax error (in the last if-else statement?) but I cannot spot it. I tried to use Chocolate's suggestions of booleans and it looks promising.


Why use for loop here instead of foreach?


Scanner in = new Scanner (System.in);
int SearchValue = in.nextlnt();
int arr[] = { 1, 2, 3, 4, 5 };

System.out.print("Please input a number: ");

for (int n: arr)
{
if (n == SearchValue)
{
System.out.println("Found");
}
else
{
System.out.println("Not found");
}
}


His first post states that he needs to use a for-loop, so that would probably be a good reason ;o)

Also this doesn't satisfy the requirement put forth in the same post, which was that, if the number is found a "Found" shall be printed, otherwise a "Not found" shall be printed after the end of the search.


Well, that's exactly what this loop does (not sure if it satisfies the "for loop" requirement since technically it is a "for loop" in Java, they call it enhanced for loop I believe). It goes through the array and if it finds a match to input it prints "Found", otherwise it prints "Not found".

I also think it's a lot nicer and 10x more efficient than regular for loop that you even break out of at some point... For loop in this case would only make sense if he would need some or all of those:
a) knowing exactly at which index the match was found
b) manipulating the array in some way, not just going through it and searching for a match to input (that's what the foreach loop is for)
c) other stuff that I'm too tired to write down now

On January 27 2014 02:07 darkness wrote:
Show nested quote +
On January 27 2014 00:32 Tobberoth wrote:
On January 26 2014 22:46 darkness wrote:
^ isn't this also called enumeration or is it called enumeration only in Objective-C?


for(NSString *aString in [array reverseObjectEnumerator])
{
NSLog(@"Value: %@",aString);
}

Wait, they call that enumeration in Objective-C? Then what do they call actual enumerations, just enum?


Well, I dunno. I've just checked those:

http://stackoverflow.com/questions/1314092/how-does-fast-enumeration-looping-work-in-objective-c-ie-for-nsstring-ast
http://www.tutorialspoint.com/objective_c/objective_c_fast_enumeration.htm


http://en.wikipedia.org/wiki/Foreach_loop#Objective-C

Much better examples and explanation
Time is precious. Waste it wisely.
Amnesty
Profile Joined April 2003
United States2054 Posts
January 26 2014 20:20 GMT
#8669
Anyone familiar with modern C++?
Can you spot any improvements minor or major in this code. This is my first attempt at working with vardic templates.
It's suppose to similar to C# string.Format("sdklfjsdklf", x, y, z)




#include <iostream>
#include <string>
#include <iterator>
#include <regex>
#include <sstream>


class bad_lexical_cast : public std::bad_cast
{
public:
bad_lexical_cast(const char * _Message = "bad lexical cast") : std::bad_cast(_Message) {}
bad_lexical_cast(const bad_lexical_cast &other) : std::bad_cast(other.what()) {}
virtual ~bad_lexical_cast() {}
};
template<typename Target, typename Source>
Target lexical_cast(Source arg)
{
std::stringstream interpreter;
Target result;
if (!(interpreter << arg) ||
!(interpreter >> result) ||
!(interpreter >> std::ws).eof())
throw bad_lexical_cast();
return result;
}
namespace detail
{
template<unsigned int Index, typename Param, typename... Args>
std::string d_format(std::string& msg, Param& t, Args&&... args)
{
return d_format<Index + 1>(d_format<Index>(msg, t), args...);
}
template<unsigned int Index, typename Param>
std::string d_format(std::string& msg, Param& t)
{
std::stringstream ss;
ss << '\\' << '{' << Index << '\\' << '}';
std::regex reg{ std::move(ss.str()) };
return std::regex_replace(msg, reg, lexical_cast<std::string>(t));
}
}
template<class... Args>
std::string format(std::string msg, Args&&... args)
{
return std::move(detail::d_format<0>(msg, args...));
}
int main()
{
int x = 10;
int y = 20;
std::string a{ format("X:{0} Y:{1} Total:{2}, Time:{3}", x, y, x + y, 3.1345995f) };
std::cout << a << std::endl;
return 0;
}


Ouput:
X:10 Y:20 Total:30, Time:3.1346
Press any key to continue . . .
The sky just is, and goes on and on; and we play all our BW games beneath it.
Cyx.
Profile Joined November 2010
Canada806 Posts
January 26 2014 20:39 GMT
#8670
On January 27 2014 03:26 Manit0u wrote:
Show nested quote +
On January 27 2014 00:03 bangsholt wrote:
On January 26 2014 22:07 Manit0u wrote:
On January 26 2014 15:53 Housemd wrote:
Update on Program:

int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30};
Scanner scan = new Scanner (System.in);
boolean x = true;
System.out.print("Please input a number");
int SearchValue = scan.nextInt();
for (int i = 0; i < array.length; i++){
if (x == true){
SearchValue = array [i];
break;
}
}
if (x){
System.out.println("Found");
}
else
{
System.out.println("Not Found");
}
}
}


Works perfectly fine for values that are in the array. For values that are not, it still prints out found. I believe that I have a small syntax error (in the last if-else statement?) but I cannot spot it. I tried to use Chocolate's suggestions of booleans and it looks promising.


Why use for loop here instead of foreach?


Scanner in = new Scanner (System.in);
int SearchValue = in.nextlnt();
int arr[] = { 1, 2, 3, 4, 5 };

System.out.print("Please input a number: ");

for (int n: arr)
{
if (n == SearchValue)
{
System.out.println("Found");
}
else
{
System.out.println("Not found");
}
}


His first post states that he needs to use a for-loop, so that would probably be a good reason ;o)

Also this doesn't satisfy the requirement put forth in the same post, which was that, if the number is found a "Found" shall be printed, otherwise a "Not found" shall be printed after the end of the search.


Well, that's exactly what this loop does (not sure if it satisfies the "for loop" requirement since technically it is a "for loop" in Java, they call it enhanced for loop I believe). It goes through the array and if it finds a match to input it prints "Found", otherwise it prints "Not found".


no it's not, yours prints out not found for every element of the array that's not the searched element ^^
zJayy962
Profile Blog Joined April 2010
1363 Posts
January 26 2014 20:46 GMT
#8671
I'm not sure if this is the right place to put this, if it isn't let me know I'll delete it.

I'm a junior right now and have finished a handful of my core courses and feel like I'm running into a brick wall. I'm applying for internships/part time work for the software world and have maybe sent out a couple dozen applications. Though this is recent I feel like I'm running into the paradox of "need experience for this job/internship" but I don't know where to get experience without getting a job/internship. All the graduates I've talked to have gotten a job fairly quickly after they got their degrees but I feel like I don't have direction and will keep running around in this paradox.
How do I get out of this infinite loop? Where can I, short of starting my own project, (which feels like a mountain that I can't climb) find this experience that every company wants me to have before getting an entry level position?
DeltaX
Profile Joined August 2011
United States287 Posts
January 26 2014 21:10 GMT
#8672
Ideally you have done some group or large projects in your classes that you can list as experience for an internship. People understand that it is unlikely that someone applying for an internship is going to have non-school experience. Make sure you are listing these projects on your resume.

I would suggest having your school's career center take a quick look at your resume if you are having issues getting called back after applying as they could also suggest improvements that may help a lot.
Manit0u
Profile Blog Joined August 2004
Poland17865 Posts
Last Edited: 2014-01-26 21:12:26
January 26 2014 21:11 GMT
#8673
On January 27 2014 05:39 Cyx. wrote:
Show nested quote +
On January 27 2014 03:26 Manit0u wrote:
On January 27 2014 00:03 bangsholt wrote:
On January 26 2014 22:07 Manit0u wrote:
On January 26 2014 15:53 Housemd wrote:
Update on Program:

int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30};
Scanner scan = new Scanner (System.in);
boolean x = true;
System.out.print("Please input a number");
int SearchValue = scan.nextInt();
for (int i = 0; i < array.length; i++){
if (x == true){
SearchValue = array [i];
break;
}
}
if (x){
System.out.println("Found");
}
else
{
System.out.println("Not Found");
}
}
}


Works perfectly fine for values that are in the array. For values that are not, it still prints out found. I believe that I have a small syntax error (in the last if-else statement?) but I cannot spot it. I tried to use Chocolate's suggestions of booleans and it looks promising.


Why use for loop here instead of foreach?


Scanner in = new Scanner (System.in);
int SearchValue = in.nextlnt();
int arr[] = { 1, 2, 3, 4, 5 };

System.out.print("Please input a number: ");

for (int n: arr)
{
if (n == SearchValue)
{
System.out.println("Found");
}
else
{
System.out.println("Not found");
}
}


His first post states that he needs to use a for-loop, so that would probably be a good reason ;o)

Also this doesn't satisfy the requirement put forth in the same post, which was that, if the number is found a "Found" shall be printed, otherwise a "Not found" shall be printed after the end of the search.


Well, that's exactly what this loop does (not sure if it satisfies the "for loop" requirement since technically it is a "for loop" in Java, they call it enhanced for loop I believe). It goes through the array and if it finds a match to input it prints "Found", otherwise it prints "Not found".


no it's not, yours prints out not found for every element of the array that's not the searched element ^^


Shit, right. That's what you get from writing stuff "on your knee" to say Especially when you want to put entire program into one method. The entire else statement should be left out of the loop body and in it's place there should be return; statement added to the if to close it after it's done its job.
Time is precious. Waste it wisely.
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
January 26 2014 21:47 GMT
#8674
On January 27 2014 05:46 zJayy962 wrote:
I'm not sure if this is the right place to put this, if it isn't let me know I'll delete it.

I'm a junior right now and have finished a handful of my core courses and feel like I'm running into a brick wall. I'm applying for internships/part time work for the software world and have maybe sent out a couple dozen applications. Though this is recent I feel like I'm running into the paradox of "need experience for this job/internship" but I don't know where to get experience without getting a job/internship. All the graduates I've talked to have gotten a job fairly quickly after they got their degrees but I feel like I don't have direction and will keep running around in this paradox.
How do I get out of this infinite loop? Where can I, short of starting my own project, (which feels like a mountain that I can't climb) find this experience that every company wants me to have before getting an entry level position?


Have you tried to join a research group in your University?

I don't know how it works where you live, but here we have research groups available for students to join, things like "Computer Graphics Research Group" where students develop various projects related to CG, tutored by a professor, or the "Mobile Computing Group" which I was part of back when I was in Uni, where we developed projects that used mobile applications to assist health care personnel in their jobs and so on.

It gave me real programming experience + a very modest but so welcome income (US$150/month :D). Later on, when I was looking for an internship I put that on my curriculum and got accepted in a small company rightaway. Before being part of the research group I applied for 3 internships and got rejected in all of them because I had 0 experience.

Not only it helped me with lunch money, experience and to get an internship, it also got half of my final paper done since I used the research as the theme of said paper!
"When the geyser died, a probe came out" - SirJolt
Amnesty
Profile Joined April 2003
United States2054 Posts
January 26 2014 21:53 GMT
#8675
On January 27 2014 05:46 zJayy962 wrote:
I'm not sure if this is the right place to put this, if it isn't let me know I'll delete it.

I'm a junior right now and have finished a handful of my core courses and feel like I'm running into a brick wall. I'm applying for internships/part time work for the software world and have maybe sent out a couple dozen applications. Though this is recent I feel like I'm running into the paradox of "need experience for this job/internship" but I don't know where to get experience without getting a job/internship. All the graduates I've talked to have gotten a job fairly quickly after they got their degrees but I feel like I don't have direction and will keep running around in this paradox.
How do I get out of this infinite loop? Where can I, short of starting my own project, (which feels like a mountain that I can't climb) find this experience that every company wants me to have before getting an entry level position?


I started applying at entry level positions in my sophomore year. I'm now a senior and landed a job a few months ago. Not an internship, an actual permanent programming position. I graduate with my four year in August. Basically, I'm going to college for a piece of paper. I've been coding as a hobby since i was 6 years old.

I basically applied to 100's and 100's of jobs over the years. Barely heard any followups from anyone. And as soon as I told them they mis-read my resume and I don't currently have a degree they usually could not get off the phone fast enough.
There are tons of people that have degrees that can't code. Companies have to shift through those, and take a chance on someone. Not having a degree to show off like others who applied your app will be almost always discarded before a phone/interview followup.

I finally, got an interview and got hired. In the interview, it was obvious to them that while i had no degree i certainly qualified for entry level positions and were pretty happy about their hire.

So you basically just keep plugging away.
The sky just is, and goes on and on; and we play all our BW games beneath it.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-01-26 23:23:59
January 26 2014 22:55 GMT
#8676
@Amnesty here's a quick breakdown. take it with a grain of salt!

class bad_lexical_cast : public std::bad_cast
{
public:
bad_lexical_cast(const char * _Message = "bad lexical cast") : std::bad_cast(_Message) {}
bad_lexical_cast(const bad_lexical_cast &other) : std::bad_cast(other.what()) {}
virtual ~bad_lexical_cast() {}
};


this is just nitpicking but i'd probably go with struct here, saves you some typing. the bad_cast exception constuctor does not take any arguments so you gotta remove that (link).

i'd drop the _Message parameter and just do return "bad lexical cast" in the overloaded what function. that way you can let the compiler generate the constructor for you, since std::bad_cast constructor does not take any arguments (link). and in addition you're just calling the default ctor anyways.

if you wanted to store some custom message you'd have to store the message as a member. i'd probably prefer std::string to const char* and then to return message.c_str(); in the what().


template<typename Target, typename Source>
Target lexical_cast(Source arg)
{
std::stringstream interpreter;
Target result;
if (!(interpreter << arg) ||
!(interpreter >> result) ||
!(interpreter >> std::ws).eof())
throw bad_lexical_cast();
return result;
}

solid.

now this really touches on code further down. i see that you are attempting to use rvalue_references, this is really tricky. check out this lecutre by scott meyers. he does a really good job of breaking down dis nasty rvalue bizness. and until you get a stronger grasp on what's up use const& whenever you can. const& binds to both l-values and r-values, as long as the variable is not being modified you can use it.

so here, where arg is not being modified you should use
Target lexical_cast(Source const& arg)


namespace detail
{
template<unsigned int Index, typename Param, typename... Args>
std::string d_format(std::string& msg, Param& t, Args&&... args)
{
return d_format<Index + 1>(d_format<Index>(msg, t), args...);
}
template<unsigned int Index, typename Param>
std::string d_format(std::string& msg, Param& t)
{
std::stringstream ss;
ss << '\\' << '{' << Index << '\\' << '}';
std::regex reg{ std::move(ss.str()) };
return std::regex_replace(msg, reg, lexical_cast<std::string>(t));
}
}


i had a different approach on this, your method might be perfectly fine (but i didn't get it to compile so i just rolled my own isntead). what i will say is that you need to get familiar when using constness and avoid rvalue references until you are sure what you are doing.

none of your functions modify the values so instead of using references and rvalue-references stick to reference to const. again since it binds to both l-value and r-values you are good to go wrt to what i think you were trying to do. you are using std::move correctly in the initalization of reg, that's pro.

in essence
	template<unsigned int Index, typename Param, typename... Args>
std::string d_format(std::string const& msg, Param const& t, Args const&... args)


as a side track writing
void func(T&&... t){
some_other_func(t...);
}

is kind of meaningless, since the r-valueness of t is lost when you pass t to some_other_func

r-values do not have names, so if at the call site of func it is called with an r-value, when you pass it through to some_other_func it now has a name and your endeavour is futile.

make sure you use forward to preserve the potential r-valueness (it's in essence a cast that makes sure r-values get passed through using reference collapsing).
void func(T&&... t){
some_other_func(std::forward<T>(t));
}

template<class... Args>
std::string format(std::string msg, Args&&... args)
{
return std::move(detail::d_format<0>(msg, args...));
}


so here you must use forward for the args, but stick to ref to const instead of rvalue reference and forward. at least until after you check out lecture.

the std::move in the return statement is redundant because of RVO.

finally remember to try{}catch(){} if you are throwing exceptions!

here's my take on your code. note i am using boost/regex instead since std::regex is not implemented yet for gcc, but ofc you can just sub boost:: with std:: since the std:: one is really just boost:: in the first place.

instead of function templates i use class templates and a static apply function to do the call, the interface is the same. don't mind the renaming, cosmetic stuff, it's me putting the lotion on the skin. i don't think you should that.

#include<boost/regex.hpp>
#include<iostream>
#include<string>
#include<sstream>

struct bad_lexical_cast:std::bad_cast{
virtual const char* what()const noexcept(true){ return "bad lexical cast"; }
virtual ~bad_lexical_cast() {}
};

template<typename target_t, typename source_t>
target_t lexical_cast(source_t const& arg){
std::stringstream interpreter;
target_t result;
if((interpreter<<arg)&&(interpreter>>result)&&(interpreter>>std::ws).eof())
return result;
throw bad_lexical_cast();
}

namespace guts{

template<unsigned int index,typename... param_T>
struct format;

template<unsigned int index,typename param_t>
struct format<index,param_t>{
static std::string apply(std::string const& msg,param_t const& param){
return boost::regex_replace(msg,boost::regex("\\{"+std::to_string(index)+"\\}"),lexical_cast<std::string>(param));
}
};

template<unsigned int index,typename param_t,typename... param_T>
struct format<index,param_t,param_T...>{
static std::string apply(std::string const& msg,param_t const& param,param_T const&... params){
return format<index+1,param_T...>::apply(format<index,param_t>::apply(msg,param),params...);
}
};

}

template<class... param_T>
std::string format(std::string const& msg,param_T const&... params){
return guts::format<0,param_T...>::apply(msg,params...);
}

int main(){
try{
int x=10;
int y=20;
std::string a{format("X:{0} Y:{1} Total:{2}, Time:{3}", x, y, x + y, 3.1345995f)};
std::cout<<a<<std::endl;
}catch(bad_lexical_cast const& e){
std::cout<<e.what()<<std::endl;
}
return 0;
}


edit:
and check out this badboy: to_string
conspired against by a confederacy of dunces.
Amnesty
Profile Joined April 2003
United States2054 Posts
Last Edited: 2014-01-27 00:19:11
January 27 2014 00:18 GMT
#8677
@ nunez

I should have said to ignore the lexical_cast stuff. Those were just quick hacks to avoid posting example code that required boost. Otherwise I would use boost::lexical_cast normally.

Thanks for the tips and vid link about r-values. I'll check it out.

I see std::to_string is only for numerics. I would assume that it's much more efficient at converting numerics to a string than the more general use of stringstream?
The sky just is, and goes on and on; and we play all our BW games beneath it.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-01-27 01:19:49
January 27 2014 01:04 GMT
#8678
ah ok, sry, it was a bit hard to gauge what to comment on!

ya, i don't know what kind of parameters that you were planning on taking, but to_string is nice if strictly numeric types!

here's (hopefully) some food for thought. imagine some goober instantiatating format (using your mock-up lexical_cast) with some weirdo type that does satisfy the requirements of your code (no overload on std::stringstream operator<< or not implicitly convertible to an already existing overload).
std::string a{format("X:{0} Y:{1} Total:{2}, Time:{3}", x, newb_t(), x + y, 3.1345995f)};

the error message he'll receive from gcc is 
g++ -c -O3 -std=c++0x -I. -Wfatal-errors  test.cpp
test.cpp: In instantiation of ‘target_t lexical_cast(const source_t&) [with target_t = std::basic_string<char>; source_t = newb_t]’:
test.cpp:42:115: required from ‘static std::string guts::format<index, param_t>::apply(const string&, const param_t&) [with unsigned int index = 1u; param_t = newb_t; std::string = std::basic_string<char>]’
test.cpp:50:83: required from ‘static std::string guts::format<index, param_t, param_T ...>::apply(const string&, const param_t&, const param_T& ...) [with unsigned int index = 1u; param_t = newb_t; param_T = {int, float}; std::string = std::basic_string<char>]’
test.cpp:50:94: required from ‘static std::string guts::format<index, param_t, param_T ...>::apply(const string&, const param_t&, const param_T& ...) [with unsigned int index = 0u; param_t = int; param_T = {newb_t, int, float}; std::string = std::basic_string<char>]’
test.cpp:58:56: required from ‘std::string format(const string&, const param_T& ...) [with param_T = {int, newb_t, int, float}; std::string = std::basic_string<char>]’
test.cpp:67:89: required from here
test.cpp:16:17: error: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’
if((interpreter<<arg)&&(interpreter>>result)&&(interpreter>>std::ws).eof())
^
compilation terminated due to -Wfatal-errors.

if you f.ex implement your cast and induce polymorphism with sfinae
	
template<class param_t,class enable=void>
struct to_string{
static_assert(sizeof(param_t)==0,"to_string trait not implemented for param_t!");
};

template<class numeric_t>
struct to_string<numeric_t,typename std::enable_if<std::is_arithmetic<numeric_t>::value>::type>{
static std::string apply(numeric_t value){
return std::to_string(value);
}
};

specializations for string (just pass it through) etc...

the same instantiation will result in an easy to read error message showing him where his template parameter is lacking and is not intrusive.
g++ -c -O3 -std=c++0x -I. -Wfatal-errors  test.cpp
test.cpp: In instantiation of ‘struct guts::to_string<newb_t, void>’:
test.cpp:43:115: required from ‘static std::string guts::format<index, param_t>::apply(const string&, const param_t&) [with unsigned int index = 1u; param_t = newb_t; std::string = std::basic_string<char>]’
test.cpp:50:83: required from ‘static std::string guts::format<index, param_t, param_T ...>::apply(const string&, const param_t&, const param_T& ...) [with unsigned int index = 1u; param_t = newb_t; param_T = {int, float}; std::string = std::basic_string<char>]’
test.cpp:50:94: required from ‘static std::string guts::format<index, param_t, param_T ...>::apply(const string&, const param_t&, const param_T& ...) [with unsigned int index = 0u; param_t = int; param_T = {newb_t, int, float}; std::string = std::basic_string<char>]’
test.cpp:58:56: required from ‘std::string format(const string&, const param_T& ...) [with param_T = {int, newb_t, int, float}; std::string = std::basic_string<char>]’
test.cpp:67:89: required from here
test.cpp:26:3: error: static assertion failed: to_string trait not implemented for param_t!
static_assert(sizeof(param_t)==0,"to_string trait not implemented for param_t!");

but lot of code to write especially as you add more and more parameters (holding on for decltype(auto) with gcc 4.9) and probably other terrible stuff too that i am unaware of. but it allows for high precision static polymorphism. i think boost::geometry is a good case study. not too terribly complex and pretty nifty design!
conspired against by a confederacy of dunces.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2014-01-27 05:49:46
January 27 2014 04:47 GMT
#8679
Hey everyone, could someone point me to a good guide on the basics of Java sounds? I want to make a program that is a simple timer that beeps at the end. However, none of the guides I have found online have been near useful. In particular, the current one works according to Eclipse, but when it tries to load the file in as an AudioInputStream it has a heart attack and dies. So any help/pointers on getting started would be nice. For example, if someone has done this in the past if you could just post the basic code of how to get a sound playing from on file that would make me a happy coder. Thanks.

Here is what I have so far:

   public Timer() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Test Sound Clip");
this.setSize(300, 200);
this.setVisible(true);

try {
// Open an audio input stream.
String urlLocation = System.getProperty("user.home") + "\\workspace\\GraemeTimer\\src\\htogether.mid";
System.out.println(urlLocation);
URL url = this.getClass().getClassLoader().getResource(urlLocation);
System.out.println(url);
AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
// Get a sound clip resource.
Clip clip = AudioSystem.getClip();
// Open audio clip and load samples from the audio input stream.
clip.open(audioIn);
clip.start();
}
catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}


It points out a Null pointer exception from the variable url(which I've printed separately and it seems to actually be null). However, every post I've seen elsewhere online has it like this, and I actually got this code from somewhere else, so I'm pretty confused about what went wrong. It's likely something with the file location but I print that as well and it looks fine. So I'm scratching my head.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
phar
Profile Joined August 2011
United States1080 Posts
January 27 2014 05:06 GMT
#8680
On January 27 2014 06:53 Amnesty wrote:
Show nested quote +
On January 27 2014 05:46 zJayy962 wrote:
I'm not sure if this is the right place to put this, if it isn't let me know I'll delete it.

I'm a junior right now and have finished a handful of my core courses and feel like I'm running into a brick wall. I'm applying for internships/part time work for the software world and have maybe sent out a couple dozen applications. Though this is recent I feel like I'm running into the paradox of "need experience for this job/internship" but I don't know where to get experience without getting a job/internship. All the graduates I've talked to have gotten a job fairly quickly after they got their degrees but I feel like I don't have direction and will keep running around in this paradox.
How do I get out of this infinite loop? Where can I, short of starting my own project, (which feels like a mountain that I can't climb) find this experience that every company wants me to have before getting an entry level position?


I started applying at entry level positions in my sophomore year. I'm now a senior and landed a job a few months ago. Not an internship, an actual permanent programming position. I graduate with my four year in August. Basically, I'm going to college for a piece of paper. I've been coding as a hobby since i was 6 years old.

I basically applied to 100's and 100's of jobs over the years. Barely heard any followups from anyone. And as soon as I told them they mis-read my resume and I don't currently have a degree they usually could not get off the phone fast enough.
There are tons of people that have degrees that can't code. Companies have to shift through those, and take a chance on someone. Not having a degree to show off like others who applied your app will be almost always discarded before a phone/interview followup.

I finally, got an interview and got hired. In the interview, it was obvious to them that while i had no degree i certainly qualified for entry level positions and were pretty happy about their hire.

So you basically just keep plugging away.

^ Yea. Shotgun approach when applying, don't feel bad if you never hear back from places. Out of the places I applied for full time jobs straight out of Uni, >50% didn't even send me back an email.

Also specifically for an internship, a lot of places won't require you to have previous work experience. For example the interns I had last summer and my intern for next summer all did not have prior work experience.
Who after all is today speaking about the destruction of the Armenians?
Prev 1 432 433 434 435 436 1032 Next
Please log in or register to reply.
Live Events Refresh
Epic.LAN
22:00
Epic.LAN 49 Group Stage
Liquipedia
GSL
21:00
GSL CK 6
IntoTheiNu 891
SHIN 118
CranKy Ducklings SOOP81
Maru 67
Zoun (SOOP) 58
herO (SOOP) 46
Solar (SOOP)41
ByuN (SOOP) 30
Rogue 24
Rex18
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko539
LamboSC2 198
MaxPax 153
SHIN 118
Maru 67
Zoun (SOOP) 58
herO (SOOP) 46
Solar (SOOP) 41
ByuN (SOOP) 30
Rogue 24
Rex 18
StarCraft: Brood War
Jaedong 2048
Horang2 991
EffOrt 680
Light 590
BeSt 423
FanTaSy 409
Soma 335
ggaemo 290
Snow 272
Mini 261
[ Show more ]
Rush 209
actioN 190
ZerO 172
Hyuk 156
Mind 116
Barracks 83
hero 80
Hyun 79
Classic 52
Yoon 51
Mong 41
sSak 36
ToSsGirL 36
Aegong 33
Shinee 33
910 30
HiyA 26
Terrorterran 24
Sharp 19
soO 19
JYJ 17
Rock 15
Bishop 15
Creator 15
zelot 13
Trap 12
Noble 11
Icarus 5
Dota 2
Gorgc19781
qojqva876
syndereN270
Fuzer 171
League of Legends
Reynor80
Counter-Strike
kRYSTAL_60
Other Games
singsing1868
olofmeister1267
B2W.Neo1020
hiko964
Mlord564
Liquid`RaSZi339
crisheroes237
DeMusliM229
ArmadaUGS132
KnowMe79
Liquid`VortiX72
QueenE35
Hui .14
ZerO(Twitch)14
Organizations
Counter-Strike
PGL20729
StarCraft: Brood War
lovetv 6
[ Show 10 non-featured ]
StarCraft 2
• StrangeGG 45
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• HerbMon 22
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
Big Brain Bouts
2h 37m
OSC
7h 37m
Replay Cast
8h 37m
Sparkling Tuna Cup
19h 37m
WardiTV Invitational
21h 37m
Epic.LAN
22h 37m
IPSL
1d 1h
eOnzErG vs McRibbed
LancerX vs StRyKeR
AI Arena Tournament
1d 3h
OSC
1d 23h
Yamato Cup
2 days
[ Show More ]
IPSL
2 days
Artosis vs RiceHat
Kyrie vs Sony
Map Test Tournament
2 days
WardiTV Weekly
2 days
Ultimate Battle
2 days
Rush vs BeSt
Replay Cast
3 days
Rogue vs Classic
Patches Events
3 days
PiGosaur Cup
4 days
Kung Fu Cup
4 days
The PondCast
5 days
KCM Race Survival
5 days
Liquipedia Results

Completed

Proleague 2026-10-28
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

IPSL Winter 2026-27
1xBet Invitational
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.