Блог пользователя Qualified

Автор Qualified, история, 6 лет назад, По-английски

Is there a difference in time between the two methods? Which one is better and why?

  • Проголосовать: нравится
  • +21
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

There is no difference in time, but using #define ll long long is not recommended by specifications, you should use typedef for defining types.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +28 Проголосовать: не нравится

The syntax using ll = long long; is more modern.

For a simple type definition it does exactly the same as typedef long long ll;

But using supports template parameters, so the concept is more powerful. In example the following definition does not work good with typedef.

template<typename T>
using MyList = std::list<T, MyAlloc<T>>;

MyList<Sometype> myList;

Since a typedef does not support template parameters we would need to 'misuse' a struct, something like this:

template<typename T>
struct MyList {
  typedef std::list<T, MyAlloc<T>> type;
};

MyList<Sometype>::type myList;
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +97 Проголосовать: не нравится

Both of these are wrong. Use #define int long long =)

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +36 Проголосовать: не нравится

print long long manually until you're master

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Use using ll = long long.

It will replace ll with long long only in contexts where ll is a type. It also makes a real type-level type alias.

#define ll long long will blindly replace ll token with long long tokens everywhere in your code even if it does not make sense. In particular, you won't be able to write ll(10.5) with #define as you could with other types like int(10.5).