Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

GrumpyDoctor posted:

"I have a doubt" is a bad translation of "I have a question," which, if I'm not mistaken, would use "pregunta" instead of "duda." I've only seen "I have a doubt" from Indians. The reason it's weird isn't connotation, it's the fact that using "doubt" as a singular noun in English is extremely uncommon.

It's both. "I have some doubts" is more grammatical but still conveys the wrong meaning.

"I have a question" just says that you're not certain about something and you'd would like more information about it. You generally follow this up by, well, asking a question. For example, "I have a question about PHP's foreign function interface. Do you know anyone who's successfully hooked it up to a functional language like Haskell?" Sometimes the question itself will strongly imply that you think there's a serious problem, but "I have a question" doesn't convey that information itself.

"I have some doubts" (or just "I have doubts") says that you understand what's being said but aren't convinced that it's true; moreover, it usually implies that you think that the claim isn't true, because if you were just uncertain you'd probably just ask a question. You generally follow this up by making an argument, sometimes couched as a question. For example, "I have some doubts about trying to implement this subsystem in Haskell. Won't frequent use of the foreign function interface introduce a lot of marshaling and locking overhead on both sides?" The statement "I have some doubts" carries a lot of skepticism itself.

Adbot
ADBOT LOVES YOU

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



FeloniousDrunk posted:

"Sure, I'll just dig in there and find out why searches aren't working like they should in this goddamn software we pay way too much money for!"

PHP code:
if($searchType == "simple"){
  $results_query = $this->XXXapi->api_prepare_simple_query($searchCollection, $searchFieldsTermsMode, $searchReturnFields, $orderby, $maxrecs, $startrecord);
} else {
  //make advanced if need be
  $results_query = $this->XXXapi->api_prepare_simple_query($searchCollection, $searchFieldsTermsMode, $searchReturnFields, $orderby, $maxrecs, $startrecord);
}
... I see. This must be some usage of the word "advanced" that I haven't encountered before.

Probably placeholder logic (plus a comment to remember why it's there) for a future advanced search feature that was never implemented so both codepaths just do the simple search. Though why it's been done at all I have no idea. It's not like it won't require an update anyway if advanced searches ever show up.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Carthag posted:

Probably placeholder logic (plus a comment to remember why it's there) for a future advanced search feature that was never implemented so both codepaths just do the simple search. Though why it's been done at all I have no idea. It's not like it won't require an update anyway if advanced searches ever show up.

You're too kind. This is at the top of the file:

php:
<?
function deleteFile( $file )
{
  if( file_exists($file)) {
    @unlink($file);
    // debug only
    // $foo = "Deleted ($file)\n";
    // $debugLog = '/logs/delete.txt';
    // file_put_contents( $debugLog , $foo );
  }
  //fclose was failing in IIS so we're checking first to see if $fp is a valid resource
  if(is_resource($fp)){
    fclose($fp);
  }
}
?>
I like that the coder implies that only IIS was failing to fclose() an uninitialized variable.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

FeloniousDrunk posted:

You're too kind. This is at the top of the file:

php:
<?
function deleteFile( $file )
{
  if( file_exists($file)) {
    @unlink($file);
    // debug only
    // $foo = "Deleted ($file)\n";
    // $debugLog = '/logs/delete.txt';
    // file_put_contents( $debugLog , $foo );
  }
  //fclose was failing in IIS so we're checking first to see if $fp is a valid resource
  if(is_resource($fp)){
    fclose($fp);
  }
}
?>
I like that the coder implies that only IIS was failing to fclose() an uninitialized variable.

This software cost actual money?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

rjmccall posted:

It's both. "I have some doubts" is more grammatical but still conveys the wrong meaning.

"I have a question" just says that you're not certain about something and you'd would like more information about it. You generally follow this up by, well, asking a question. For example, "I have a question about PHP's foreign function interface. Do you know anyone who's successfully hooked it up to a functional language like Haskell?" Sometimes the question itself will strongly imply that you think there's a serious problem, but "I have a question" doesn't convey that information itself.

"I have some doubts" (or just "I have doubts") says that you understand what's being said but aren't convinced that it's true; moreover, it usually implies that you think that the claim isn't true, because if you were just uncertain you'd probably just ask a question. You generally follow this up by making an argument, sometimes couched as a question. For example, "I have some doubts about trying to implement this subsystem in Haskell. Won't frequent use of the foreign function interface introduce a lot of marshaling and locking overhead on both sides?" The statement "I have some doubts" carries a lot of skepticism itself.

Yeah this is what I meant about it having a negative connotation in English. I just want to restate that in Spanish we use I have a doubt almost interchangeably with I have a question, usually if it's something that needs to be clarified while a question is something out of the blue.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I, too, have some doubts about a PHP / Haskell function foreign interface. Many, actually.

raminasi
Jan 25, 2005

a last drink with no ice

rjmccall posted:

It's both. "I have some doubts" is more grammatical but still conveys the wrong meaning.

"I have a question" just says that you're not certain about something and you'd would like more information about it. You generally follow this up by, well, asking a question. For example, "I have a question about PHP's foreign function interface. Do you know anyone who's successfully hooked it up to a functional language like Haskell?" Sometimes the question itself will strongly imply that you think there's a serious problem, but "I have a question" doesn't convey that information itself.

"I have some doubts" (or just "I have doubts") says that you understand what's being said but aren't convinced that it's true; moreover, it usually implies that you think that the claim isn't true, because if you were just uncertain you'd probably just ask a question. You generally follow this up by making an argument, sometimes couched as a question. For example, "I have some doubts about trying to implement this subsystem in Haskell. Won't frequent use of the foreign function interface introduce a lot of marshaling and locking overhead on both sides?" The statement "I have some doubts" carries a lot of skepticism itself.

Yes, but I've never seen "I have some doubts" as a poor stand-in for "I have a question." It's always been my opinion that "I have a doubt" is so weird on its face that its connotation never even factors into its interpretation, but I guess that's not something universal.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

GrumpyDoctor posted:

Yes, but I've never seen "I have some doubts" as a poor stand-in for "I have a question." It's always been my opinion that "I have a doubt" is so weird on its face that its connotation never even factors into its interpretation, but I guess that's not something universal.

I agree that it's wrong enough that nobody mistakes it for correct English meaning something else.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

rjmccall posted:

I agree that it's wrong enough that nobody mistakes it for correct English meaning something else.

It's Indian English.

quote:

July 12, 2006
Vishy's Indian English Dictionary: doubt

doubt. /DOWT/. A question asking for clarification. In standard English and American, the noun doubt is uncountable and refers to a lack of complete trust in something. Doubt may be expressed as simply as doubting someone's abilities or as profoundly as someone doubting their own religious faith. Not so in India. In India, doubt can be used as a countable noun. When a school teacher goes over an intricate concept in class, she invariably leaves some students with doubts in their mind about their understanding of the material just covered. Students ask her questions to get a better understanding of the concept and each such question is called a doubt. It is entirely normal to hear a statement like "I have just one doubt, miss" or "If you have any doubts before the exam tomorrow, come see me in the staff room".
http://english.stackexchange.com/questions/2429/can-doubt-sometimes-mean-question

zergstain
Dec 15, 2005

We have case insensitive versions of wcscmp() and wcsncmp() which call a function on both inputs that allocates a buffer to store an uppercase copy of the string, and returns -1 if one of the allocations fail. There's also this:
code:

for (i = 0; (size_t)i < len; i++) {
        res[i] = towupper(res[i]);
}
res is the freshly malloc()d and uninitialized buffer.

Fortunately a quick grep says nothing anywhere uses these functions, so I have permission to just axe all of it.

Edit: never mind, the usage is obscured by macros.

zergstain fucked around with this message at 19:43 on May 17, 2013

Pilsner
Nov 23, 2002

Can terrible color schemes go in here too? Just found this explosion of unreadability.



Seriously, gently caress "dark themes" for coding. :colbert:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Pilsner posted:

Seriously, gently caress "dark themes" for coding. :colbert:

Sorry about your bad opinions.

Salynne
Oct 25, 2007

Pilsner posted:

Seriously, gently caress "dark themes" for coding. :colbert:



Dark themes own? That particular one you had was quite bad though.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Dark themes are seriously cool, when you're spending your whole day staring at a screen you really don't want it to have a glaring bright background.

Also Hammerite is there a trailing space on every single one of your lines, or is your theme just misleading like that?

Dirk Pitt
Sep 14, 2007

haha yes, this feels good

Toilet Rascal

Pilsner posted:

Can terrible color schemes go in here too? Just found this explosion of unreadability.



Seriously, gently caress "dark themes" for coding. :colbert:

That one is ridiculous, but the visual studio dark theme is quite nice for c#.

My only problem is when I copy out code and paste it in lync, to ask a question, the font colors come, but the dark background doesn't.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

General Olloth posted:



Dark themes own? That particular one you had was quite bad though.

What theme is this? ST2, I assume?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Jabor posted:

Dark themes are seriously cool, when you're spending your whole day staring at a screen you really don't want it to have a glaring bright background.

Also Hammerite is there a trailing space on every single one of your lines, or is your theme just misleading like that?

A programmer I work with is extremely sensitive to light - his background is muddy gray and his text is black. He can't look at a normal monitor with normal themes without visibly flinching though, it must suck to have to develop and be really sensitive to light from computer monitors.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Jabor posted:

Dark themes are seriously cool, when you're spending your whole day staring at a screen you really don't want it to have a glaring bright background.

Also Hammerite is there a trailing space on every single one of your lines, or is your theme just misleading like that?

It just looks like that.

It never occurred to me to find fault with it until now. Thanks a lot jerk!!!!!

Foiltha
Jun 12, 2008

Blinkz0rz posted:

What theme is this? ST2, I assume?

Looks like Obsidian.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Jabor posted:

Also Hammerite is there a trailing space on every single one of your lines, or is your theme just misleading like that?

I'd guess it's just the newline character.

Lorem ipsum
Sep 25, 2007
IF I REPORT SOMETHING, BAN ME.
The dissassembly for the 2ms delay library function for Microchip's C Hi-Tech Compiler:

code:
371:               __delay_ms(4);
  220D    300B     MOVLW 0xb
  220E    0022     MOVLB 0x2
  220F    00AC     MOVWF 0x2c
  2210    3062     MOVLW 0x62
  2211    00AB     MOVWF 0x2b
  2212    0BAB     DECFSZ 0x2b, F
  2213    2A12     GOTO 0x212
  2214    0BAC     DECFSZ 0x2c, F
  2215    2A12     GOTO 0x212
  2216    0064     CLRWDT
Just the fact that any built-in function would clear the watchdog timer is :psyduck:, but it is far worse than that.

From the compiler documentation:
code:
Note that if the _delay feature is used to insert a simple delay
sequence or loop, the CLRWDT instruction may be used in this sequence.
If the watchdog timer is not being used, this is of no concern. If the
watchdog timer is enabled, then be aware that delays may reset its
timer.
"may"

Apparently a 6 or 10ms delay does not reset the wdt! First, thanks for the super ambiguous wording. Second, thanks for making using a watchdog useless for code with 2ms delays!

The Gripper
Sep 14, 2004
i am winner

Lorem ipsum posted:

Apparently a 6 or 10ms delay does not reset the wdt! First, thanks for the super ambiguous wording. Second, thanks for making using a watchdog useless for code with 2ms delays!
There's *probably* a (stupid) reason for it along the lines of "hey if you're intentionally using a long delay you probably don't want your wtd to time out so here's some useful thing" (most likely due to a first-party library requiring it) but documenting it in that stupid way makes it obnoxious as poo poo plus the solution breaks the watchdog timer unless you code as if "may" is a definite.

In other news, Microchip support is pretty bad and I'm really not surprised at all.

Lysandus
Jun 21, 2010
Ok, which of you did this.
Fizz Buzz Enterprise Edition

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Naturally, there's no goddamned documentation. :argh:

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Volmarias posted:

Naturally, there's no goddamned documentation. :argh:

Who needs documentation with abstractions that clear?

I once did an enterprise Hello World in Rails (it may actually be further back in this thread) where there was a model for each character, each phrase, and then a join table between them. The readme file didn't give away that it was supposed to be tongue-in-cheek, so I made sure to delete it from my public Github before a recent job interview because the last thing I wanted was someone finding my GH account and getting the wrong idea.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Too readable. I should take a crack at doing this my company's way.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Just browsing through the packages made me laugh :allears: there's even two java folders, hahaha

Then I got to FizzBuzz.java :catstare: oh god...

Lorem ipsum
Sep 25, 2007
IF I REPORT SOMETHING, BAN ME.

The Gripper posted:

In other news, Microchip support is pretty bad and I'm really not surprised at all.

Yea, I put in a ticket and the response was literally "Yea that's a bug please buy our new $1000 compiler in which we have fixed it"

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

You might think that's a joke, but lots of people advocate the enterprise approach.

Volte
Oct 4, 2004

woosh woosh
I'm dying

That Turkey Story
Mar 30, 2003

For my good friend Suspicious Dish:

C++ code:
#include <boost/preprocessor/arithmetic/mod.hpp>
#include <boost/preprocessor/control/expr_iif.hpp>
#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/logical/bitor.hpp>
#include <boost/preprocessor/logical/not.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>

#define FIZZBUZZ()                                                             \
static_assert( false, BOOST_PP_REPEAT_FROM_TO( 1, 101, FIZZBUZZ_MAC, ~ ) );

#define FIZZBUZZ_MAC( z, i, dummy )                                            \
FIZZBUZZ_MAC_IMPL( i, BOOST_PP_NOT( BOOST_PP_MOD( i, 3 ) )                     \
                    , BOOST_PP_NOT( BOOST_PP_MOD( i, 5 ) )                     \
                 )

#define FIZZBUZZ_MAC_IMPL( i, div_by_3, div_by_5 )                             \
BOOST_PP_IIF( BOOST_PP_BITOR( div_by_3, div_by_5 )                             \
            , FIZZBUZZ_MAC_IMPL_FIZZ_OR_BUZZ                                   \
            , FIZZBUZZ_MAC_IMPL_NOT_FIZZ_OR_BUZZ                               \
            )( i, div_by_3, div_by_5 )

#define FIZZBUZZ_MAC_IMPL_FIZZ_OR_BUZZ( i, div_by_3, div_by_5 )                \
BOOST_PP_EXPR_IIF( div_by_3, "Fizz" ) BOOST_PP_EXPR_IIF( div_by_5, "Buzz" ) " "

#define FIZZBUZZ_MAC_IMPL_NOT_FIZZ_OR_BUZZ( i, div_by_3, div_by_5 ) #i " "

FIZZBUZZ()

Volte
Oct 4, 2004

woosh woosh
C++ code:
#include <cstdio>
 
template <bool cond, typename T, typename F>
struct tpl_if {
  typedef T val;
};
 
template <typename T, typename F>
struct tpl_if<false, T, F> {
  typedef F val;
};
 
 
template <int iter_outer>
class fizz {
  
  template <int iter, int temp, bool ones, char... c>
  struct fizz_impl {
    static char *go() {
      const int digit = temp % 10;
      const int next = temp / 10;
 
      typedef
      typename tpl_if<
        iter % 15 == 0,
    fizz_impl<iter-1, iter-1, true, 'f', 'i', 'z', 'z', 'b', 'u', 'z', 'z', ' ', c...>,
        typename tpl_if<
          iter % 5 == 0,
          fizz_impl<iter-1, iter-1, true, 'b', 'u', 'z', 'z', ' ', c...>,
          typename tpl_if<
            iter % 3 == 0,
            fizz_impl<iter-1, iter-1, true, 'f', 'i', 'z', 'z', ' ', c...>,
            typename tpl_if<
              ones,
              fizz_impl<iter, next, false, digit + '0', ' ', c...>,
              fizz_impl<iter, next, false, digit + '0', c...>
            >::val
          >::val
        >::val
      >::val branch;
      
      return branch::go();
    }
  };
 
  template<int iter, bool ones, char... c>
  struct fizz_impl<iter, 0, ones, c...> {
    static char *go() {
      return fizz_impl<iter-1, iter-1, true, c...>::go();
    }
  };
 
  template<bool ones, char... c>
  struct fizz_impl<0, 0, ones, c...> {
    static char *go() {
      static char r[] = { c... };
      return r;
    }
  };
        
public:
  static char *go() {
    return fizz_impl<iter_outer, iter_outer, true>::go();
  }
};
 
int main() {
  printf("%s", fizz<100>::go());
}

KaneTW
Dec 2, 2011


quote:

fizzbuzz.cpp:27:1: error: static assertion failed: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz

This is beautiful.

Salynne
Oct 25, 2007

Blinkz0rz posted:

What theme is this? ST2, I assume?

Yeah, Obsidian like the other guy said.

http://eclipsecolorthemes.org/?view=theme&id=21

I think I changed maybe one of the colors.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

That Turkey Story posted:

For my good friend Suspicious Dish:

Finally, the one good use of boost::preprocessor has been found.

I love you, that's amazing.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
This is not particularly clever, but I thought I'd contribute anyway.
JavaScript code:
(function () {
    var seed = ["fizzbuzz", null, null, "fizz", null, "buzz", "fizz", null, null, "fizz", "buzz", null, "fizz", null, null];
    for (var i = 1; i <= 100; i++) {
        console.log(seed[i%seed.length] || i);
    }
})()

Salynne
Oct 25, 2007
You guys are way over engineering it.

code:
public class FizzBuzz {
	public static final String fizzbuzz = "1\n" +
			"2\n" +
			"Fizz\n" +
			"4\n" +
			"Buzz\n" +
			"Fizz\n" +
			"7\n" +
			"8\n" +
			"Fizz\n" +
			"Buzz\n" +
			"11\n" +
			"Fizz\n" +
			"13\n" +
			"14\n" +
			"FizzBuzz\n" +
			"16\n" +
			"17\n" +
			"Fizz\n" +
			"19\n" +
			"Buzz\n" +
			"Fizz\n" +
			"22\n" +
			"23\n" +
			"Fizz\n" +
			"Buzz\n" +
			"26\n" +
			"Fizz\n" +
			"28\n" +
			"29\n" +
			"FizzBuzz\n" +
			"31\n" +
			"32\n" +
			"Fizz\n" +
			"34\n" +
			"Buzz\n" +
			"Fizz\n" +
			"37\n" +
			"38\n" +
			"Fizz\n" +
			"Buzz\n" +
			"41\n" +
			"Fizz\n" +
			"43\n" +
			"44\n" +
			"FizzBuzz\n" +
			"46\n" +
			"47\n" +
			"Fizz\n" +
			"49\n" +
			"Buzz\n" +
			"Fizz\n" +
			"52\n" +
			"53\n" +
			"Fizz\n" +
			"Buzz\n" +
			"56\n" +
			"Fizz\n" +
			"58\n" +
			"59\n" +
			"FizzBuzz\n" +
			"61\n" +
			"62\n" +
			"Fizz\n" +
			"64\n" +
			"Buzz\n" +
			"Fizz\n" +
			"67\n" +
			"68\n" +
			"Fizz\n" +
			"Buzz\n" +
			"71\n" +
			"Fizz\n" +
			"73\n" +
			"74\n" +
			"FizzBuzz\n" +
			"76\n" +
			"77\n" +
			"Fizz\n" +
			"79\n" +
			"Buzz\n" +
			"Fizz\n" +
			"82\n" +
			"83\n" +
			"Fizz\n" +
			"Buzz\n" +
			"86\n" +
			"Fizz\n" +
			"88\n" +
			"89\n" +
			"FizzBuzz\n" +
			"91\n" +
			"92\n" +
			"Fizz\n" +
			"94\n" +
			"Buzz\n" +
			"Fizz\n" +
			"97\n" +
			"98\n" +
			"Fizz\n" +
			"Buzz";

	public static void main(String[] args) {
		System.out.println(fizzbuzz);
	}
}
Clean and simple.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

code:
#!/usr/bin/env python

import random

for i in range(0, 100):
    if not i % 15:
        random.seed(1178741599)
    print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)]
I plan on memorizing that seed for my next job interview.

senrath
Nov 4, 2009

Look Professor, a destruct switch!


You are all monsters, and I love it.

Adbot
ADBOT LOVES YOU

That Turkey Story
Mar 30, 2003

Volte posted:

<snip template metaprogrammed fizzbuzz>

I wanted to go and do it anyway:

C++ code:
#include <iostream>
#include <type_traits>

template< char... C >
struct tmp_string
{
  typedef tmp_string type;
  static char const c_string[ sizeof...( C ) + 1 ];
};

template< char... C >
char const tmp_string< C... >::c_string[ sizeof...( C ) + 1 ]
  = { C..., '\0' };

template< class... Strings > struct combine;

template< char... LC, char... RC >
struct combine< tmp_string< LC... >, tmp_string< RC... > >
  : tmp_string< LC..., RC... > {};

template< class L, class R, class... Strings >
struct combine< L, R, Strings... >
  : combine< typename combine< L, R >::type, Strings... > {};

template< unsigned Digit > struct digit_to_string
  : tmp_string< static_cast< char >( '0' + Digit ) > {};

template< unsigned Value, class CurrString >
struct value_to_string_impl
  : value_to_string_impl
    < Value / 10
    , typename combine
      < typename digit_to_string< Value % 10 >::type
      , CurrString
      >::type
    > {};

template< class CurrString >
struct value_to_string_impl< 0, CurrString > : CurrString {};

template< unsigned Value >
struct value_to_string : value_to_string_impl< Value, tmp_string<> > {};

template<> struct value_to_string< 0 > : tmp_string< '0' > {};

template< unsigned Curr, unsigned End >
struct fizzbuzz_impl;

template< unsigned Curr, unsigned End >
struct fizzbuzz_impl_fizz_or_buzz
  : combine
    < typename std::conditional
      < Curr % 3 == 0, tmp_string< 'F', 'i', 'z', 'z' >, tmp_string<> >::type
    , typename std::conditional
      < Curr % 5 == 0, tmp_string< 'B', 'u', 'z', 'z' >, tmp_string<> >::type
    , tmp_string< ' ' >
    , typename fizzbuzz_impl< Curr + 1, End >::type
    > {};

template< unsigned Curr, unsigned End >
struct fizzbuzz_impl_not_fizz_or_buzz
  : combine
    < typename value_to_string< Curr >::type
    , tmp_string< ' ' >
    , typename fizzbuzz_impl< Curr + 1, End >::type
    > {};

template< unsigned Curr, unsigned End >
struct fizzbuzz_impl
  : std::conditional< Curr % 3 == 0 || Curr % 5 == 0
                    , fizzbuzz_impl_fizz_or_buzz< Curr, End >
                    , fizzbuzz_impl_not_fizz_or_buzz< Curr, End >
                    >::type {};

template< unsigned Curr >
struct fizzbuzz_impl< Curr, Curr > : tmp_string<> {};

typedef fizzbuzz_impl< 1, 101 >::type fizzbuzz;

int main()
{
  std::cout << fizzbuzz::c_string;
}
This one produces a single, c-style string at compile time.

That Turkey Story fucked around with this message at 18:22 on May 20, 2013

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply