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.
 
  • Locked thread
GeneralZod
May 28, 2003

Kneel before Zod!
Grimey Drawer

leper khan posted:

I said they were identical except default public/private, he told me I was wrong, then I pulled out the relevant section of the specification (which I keep on my iPad), and told him he was probably thinking of POD types, but that classes could also be POD types, and nothing stopped a struct from not being a POD.

Did he tell you "the answer", in the end?

Adbot
ADBOT LOVES YOU

GeneralZod
May 28, 2003

Kneel before Zod!
Grimey Drawer
I know C++ pretty well, but would struggle with that question, assuming it means "features that are in C++11 and not in prior releases".

Maybe I'd go for:

- The introduction of std::bind, which was almost wholly useless even in C++11 and is entirely useless in C++14;
- Personal taste - I don't like that std::thread begins executing on construction (edit: ah - apparently this might be a necessity on some platforms);
- The standardisation of the clunkier e.g std::enable_if<T>::type rather than C++14's less clunky e.g. std::enable_if_t<T>;
- Making constexpr methods implicitly const (rescinded in C++14).

GeneralZod fucked around with this message at 14:14 on Aug 16, 2016

GeneralZod
May 28, 2003

Kneel before Zod!
Grimey Drawer
Seems to work with recent clang and gcc:

code:
#include <type_traits>

#define class struct // Comment me out for compilability!

class A
{
    static int f()
    {
        return 0;
    };
};

template <typename T>
class B
{
    public:
        template <typename U, typename = decltype(U::f())>
        static void g(U u);

        static int g(...);
        typedef decltype(g(std::declval<T>())) bloo;
};

int main()
{
    B<A>::bloo x;
}
Maybe using type traits is cheating, but here's another one anyway:

code:
#include <type_traits>

#define class struct // Comment me out for compilability!

class A
{
    int i;
    private:
    int j;
};

template <typename T>
class B
{
};

template <>
class B<std::false_type>;

int main()
{
    B<typename std::is_pod<A>::type> b;
}

GeneralZod fucked around with this message at 20:40 on Aug 23, 2016

GeneralZod
May 28, 2003

Kneel before Zod!
Grimey Drawer

qntm posted:

What is wrong with that?

There are probably other examples, but try:

code:
#include <iostream>

using namespace std;

#define ADD(x, y) x + y

template <typename T>
T add(const T& x, const T& y)
{
    return x + y;
}

int main()
{
    // The fact that I'm having to use printf instead of cout is bug #1 :p
    printf("Normal add %d Macro ADD: %d\n", add(3 & 3, 4), ADD(3 & 3, 4));
    printf("Normal add %d Macro ADD: %d\n", add(3, 5 & 3), ADD(3, 5 & 3));
    printf("Normal add %d Macro ADD: %d\n", 5 * add(1, 2), 5 * ADD(1, 2));
}


edit:

For further fun, try:

code:
#include <iostream>

using namespace std;

#define ADD(x, y) x + y

template <typename T, typename U>
class TwoTemplateTypes
{
    public:
        const static int value = 1;
};
template<typename T, typename U> 
const int TwoTemplateTypes<T, U>::value;

template <typename T>
T add(const T& x, const T& y)
{
    return x + y;
}

int main()
{
    printf("Normal add %d Macro ADD: %d\n", add(TwoTemplateTypes<int, int>::value, 2), 
            ADD(TwoTemplateTypes<int, int>::value, 2)
            );
}

GeneralZod fucked around with this message at 13:37 on Aug 24, 2016

  • Locked thread