Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d

What are traits in D?

Mohe Ud Din Sheikh

Overview

In D, we use traits to get internal compiler information, which helps us use functions and variables differently and makes it more beneficial for programming.

Syntax


  writeln(__traits(isFloating, float));
Syntax
  • Here, we use __traits to call the traits functionality. After that, we use isFloating to check if the argument is a float type. It returns true or false.

Example

import std.stdio;

void main() {
  int i;
  float t;
  // Used the traits
  writeln(__traits(isFloating, i));
  writeln(__traits(isFloating, t));
  
}

Explanation

  • Lines 7 and 8: We use the traits method in which we use isFloating as the keyword. It identifies if the passed parameter is of the float type. It returns the result as true if the value is float. Otherwise, it returns false.

RELATED TAGS

d

CONTRIBUTOR

Mohe Ud Din Sheikh
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring