Click here to Skip to main content
15,914,013 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Writeprivateprofilestring() take delay to update original ini file Pin
David Crow17-May-10 3:08
David Crow17-May-10 3:08 
Questionwmv blank file creation Pin
mohan_chandra8416-May-10 20:29
mohan_chandra8416-May-10 20:29 
Questionreleated to netdefender firewall Pin
promila jangra16-May-10 6:00
promila jangra16-May-10 6:00 
QuestionUseing UTF-8 in CHttpFile Pin
m_code16-May-10 5:27
m_code16-May-10 5:27 
AnswerRe: Useing UTF-8 in CHttpFile Pin
Richard MacCutchan16-May-10 6:26
mveRichard MacCutchan16-May-10 6:26 
GeneralRe: Useing UTF-8 in CHttpFile Pin
m_code16-May-10 7:51
m_code16-May-10 7:51 
GeneralRe: Useing UTF-8 in CHttpFile Pin
Richard MacCutchan16-May-10 11:13
mveRichard MacCutchan16-May-10 11:13 
GeneralRe: Useing UTF-8 in CHttpFile Pin
m_code16-May-10 21:09
m_code16-May-10 21:09 
GeneralRe: Useing UTF-8 in CHttpFile Pin
Richard MacCutchan17-May-10 1:15
mveRichard MacCutchan17-May-10 1:15 
QuestionJPEG to Cur Conversion Pin
ForNow15-May-10 17:07
ForNow15-May-10 17:07 
AnswerRe: JPEG to Cur Conversion Pin
Code-o-mat16-May-10 0:19
Code-o-mat16-May-10 0:19 
GeneralRe: JPEG to Cur Conversion Pin
ForNow16-May-10 7:10
ForNow16-May-10 7:10 
GeneralRe: JPEG to Cur Conversion Pin
Code-o-mat16-May-10 8:38
Code-o-mat16-May-10 8:38 
GeneralRe: JPEG to Cur Conversion Pin
ForNow16-May-10 8:51
ForNow16-May-10 8:51 
GeneralRe: JPEG to Cur Conversion Pin
Code-o-mat16-May-10 11:47
Code-o-mat16-May-10 11:47 
GeneralRe: JPEG to Cur Conversion --- Awicons did the trick Pin
ForNow16-May-10 8:35
ForNow16-May-10 8:35 
QuestionSolved - Two-Dimensional Array not reading right [modified] Pin
Frank Robertson15-May-10 16:20
Frank Robertson15-May-10 16:20 
AnswerRe: Two-Dimensional Array not reading right Pin
Luc Pattyn15-May-10 17:36
sitebuilderLuc Pattyn15-May-10 17:36 
GeneralRe: Two-Dimensional Array not reading right Pin
Frank Robertson15-May-10 19:30
Frank Robertson15-May-10 19:30 
GeneralRe: Two-Dimensional Array not reading right Pin
Luc Pattyn16-May-10 1:07
sitebuilderLuc Pattyn16-May-10 1:07 
GeneralRe: Two-Dimensional Array not reading right Pin
Frank Robertson17-May-10 13:00
Frank Robertson17-May-10 13:00 
GeneralCongrats Pin
Luc Pattyn17-May-10 13:11
sitebuilderLuc Pattyn17-May-10 13:11 
GeneralRe: Two-Dimensional Array not reading right Pin
Iain Clarke, Warrior Programmer16-May-10 20:49
Iain Clarke, Warrior Programmer16-May-10 20:49 
AnswerRe: Two-Dimensional Array not reading right Pin
Aescleal15-May-10 22:42
Aescleal15-May-10 22:42 
Hi Frank,

Just to expand a bit on Luc's comment above, there's usually a simpler way of doing things when you see repeated code. Have a look at the facilities provided by the <algorithm> header, you'll find plenty of ways to simplify loops. In your case you're transforming the contents of one collection into the contents of another which is exactly what std::transform does.

So taking Luc's comments one stage further you can do most of what you were trying to do with your initialisation loops in two lines:

std::transform( hand, hand + 5, handColumn, []( int n ){ return n / 13; } );
std::transform( hand, hand + 5, handRow,    []( int n ){ return n % 13; } );


The arguments to std::transform are a bit weird looking if you've never seen them before:
- the first two describe where you want to get the data to transform from
- the third describes where you want to put the transformed data
- the fourth describes how you want to transform it

So in both cases you're wanting to operate on data from hand[ 0 ] to hand[ 5 ] (not including hand[ 5 ]) and stick the transformed data into handRow or handColumn starting at the beginning. The last parameter is a lambda (it starts with empty square brackets)that says what you want the tranformation to be division by 13 in the first case and modulo by 13 in the second case.

(lambda's are inline objects that behave like function calls. They're part of the C++0x standard - VC++ 2010 and gcc 4.4 support them though so it's easy to get a free compiler that knows about them.)

Going a bit further... even with these changes it takes a bit of looking at the code to work out what's going on. As far as I can tell you're taking an integer representation of a playing card and decoding it into an integer representation of a suit and a card face. Both aren't that obvious - it looks like you're missing a few abstractions in your code. If you had these abstractions you wouldn't be worrying about decoding the card's suit and face value from an integer, it'd just happen.

Anyway, I can witter on a bit more if you want - otherwise the important message to take from this is handcrafted loops are often not as effective as taking an algorithm from <algorithm> and applying it.

Cheers,

Ash
GeneralRe: Two-Dimensional Array not reading right Pin
Frank Robertson16-May-10 0:51
Frank Robertson16-May-10 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.