• Guest
HabraHabr
  • Main
  • Users

  • Development
    • Programming
    • Information Security
    • Website development
    • JavaScript
    • Game development
    • Open source
    • Developed for Android
    • Machine learning
    • Abnormal programming
    • Java
    • Python
    • Development of mobile applications
    • Analysis and design of systems
    • .NET
    • Mathematics
    • Algorithms
    • C#
    • System Programming
    • C++
    • C
    • Go
    • PHP
    • Reverse engineering
    • Assembler
    • Development under Linux
    • Big Data
    • Rust
    • Cryptography
    • Entertaining problems
    • Testing of IT systems
    • Testing Web Services
    • HTML
    • Programming microcontrollers
    • API
    • High performance
    • Developed for iOS
    • CSS
    • Industrial Programming
    • Development under Windows
    • Image processing
    • Compilers
    • FPGA
    • Professional literature
    • OpenStreetMap
    • Google Chrome
    • Data Mining
    • PostgreSQL
    • Development of robotics
    • Visualization of data
    • Angular
    • ReactJS
    • Search technologies
    • Debugging
    • Test mobile applications
    • Browsers
    • Designing and refactoring
    • IT Standards
    • Solidity
    • Node.JS
    • Git
    • LaTeX
    • SQL
    • Haskell
    • Unreal Engine
    • Unity3D
    • Development for the Internet of things
    • Functional Programming
    • Amazon Web Services
    • Google Cloud Platform
    • Development under AR and VR
    • Assembly systems
    • Version control systems
    • Kotlin
    • R
    • CAD/CAM
    • Customer Optimization
    • Development of communication systems
    • Microsoft Azure
    • Perfect code
    • Atlassian
    • Visual Studio
    • NoSQL
    • Yii
    • Mono и Moonlight
    • Parallel Programming
    • Asterisk
    • Yandex API
    • WordPress
    • Sports programming
    • Lua
    • Microsoft SQL Server
    • Payment systems
    • TypeScript
    • Scala
    • Google API
    • Development of data transmission systems
    • XML
    • Regular expressions
    • Development under Tizen
    • Swift
    • MySQL
    • Geoinformation services
    • Global Positioning Systems
    • Qt
    • Dart
    • Django
    • Development for Office 365
    • Erlang/OTP
    • GPGPU
    • Eclipse
    • Maps API
    • Testing games
    • Browser Extensions
    • 1C-Bitrix
    • Development under e-commerce
    • Xamarin
    • Xcode
    • Development under Windows Phone
    • Semantics
    • CMS
    • VueJS
    • GitHub
    • Open data
    • Sphinx
    • Ruby on Rails
    • Ruby
    • Symfony
    • Drupal
    • Messaging Systems
    • CTF
    • SaaS / S+S
    • SharePoint
    • jQuery
    • Puppet
    • Firefox
    • Elm
    • MODX
    • Billing systems
    • Graphical shells
    • Kodobred
    • MongoDB
    • SCADA
    • Hadoop
    • Gradle
    • Clojure
    • F#
    • CoffeeScript
    • Matlab
    • Phalcon
    • Development under Sailfish OS
    • Magento
    • Elixir/Phoenix
    • Microsoft Edge
    • Layout of letters
    • Development for OS X
    • Forth
    • Smalltalk
    • Julia
    • Laravel
    • WebGL
    • Meteor.JS
    • Firebird/Interbase
    • SQLite
    • D
    • Mesh-networks
    • I2P
    • Derby.js
    • Emacs
    • Development under Bada
    • Mercurial
    • UML Design
    • Objective C
    • Fortran
    • Cocoa
    • Cobol
    • Apache Flex
    • Action Script
    • Joomla
    • IIS
    • Twitter API
    • Vkontakte API
    • Facebook API
    • Microsoft Access
    • PDF
    • Prolog
    • GTK+
    • LabVIEW
    • Brainfuck
    • Cubrid
    • Canvas
    • Doctrine ORM
    • Google App Engine
    • Twisted
    • XSLT
    • TDD
    • Small Basic
    • Kohana
    • Development for Java ME
    • LiveStreet
    • MooTools
    • Adobe Flash
    • GreaseMonkey
    • INFOLUST
    • Groovy & Grails
    • Lisp
    • Delphi
    • Zend Framework
    • ExtJS / Sencha Library
    • Internet Explorer
    • CodeIgniter
    • Silverlight
    • Google Web Toolkit
    • CakePHP
    • Safari
    • Opera
    • Microformats
    • Ajax
    • VIM
  • Administration
    • System administration
    • IT Infrastructure
    • *nix
    • Network technologies
    • DevOps
    • Server Administration
    • Cloud computing
    • Configuring Linux
    • Wireless technologies
    • Virtualization
    • Hosting
    • Data storage
    • Decentralized networks
    • Database Administration
    • Data Warehousing
    • Communication standards
    • PowerShell
    • Backup
    • Cisco
    • Nginx
    • Antivirus protection
    • DNS
    • Server Optimization
    • Data recovery
    • Apache
    • Spam and antispam
    • Data Compression
    • SAN
    • IPv6
    • Fidonet
    • IPTV
    • Shells
    • Administering domain names
  • Design
    • Interfaces
    • Web design
    • Working with sound
    • Usability
    • Graphic design
    • Design Games
    • Mobile App Design
    • Working with 3D-graphics
    • Typography
    • Working with video
    • Work with vector graphics
    • Accessibility
    • Prototyping
    • CGI (graphics)
    • Computer Animation
    • Working with icons
  • Control
    • Careers in the IT industry
    • Project management
    • Development Management
    • Personnel Management
    • Product Management
    • Start-up development
    • Managing the community
    • Service Desk
    • GTD
    • IT Terminology
    • Agile
    • Business Models
    • Legislation and IT-business
    • Sales management
    • CRM-systems
    • Product localization
    • ECM / EDS
    • Freelance
    • Venture investments
    • ERP-systems
    • Help Desk Software
    • Media management
    • Patenting
    • E-commerce management
    • Creative Commons
  • Marketing
    • Conferences
    • Promotion of games
    • Internet Marketing
    • Search Engine Optimization
    • Web Analytics
    • Monetize Web services
    • Content marketing
    • Monetization of IT systems
    • Monetize mobile apps
    • Mobile App Analytics
    • Growth Hacking
    • Branding
    • Monetize Games
    • Display ads
    • Contextual advertising
    • Increase Conversion Rate
  • Sundry
    • Reading room
    • Educational process in IT
    • Research and forecasts in IT
    • Finance in IT
    • Hakatonas
    • IT emigration
    • Education abroad
    • Lumber room
    • I'm on my way

Auto - the pros and cons of

Introduction
 
Kind time of the day, friends! Today we will talk about the operator auto in C ++.
 
A little background: this operator came to us in C ++ 11 and since then has deeply entered into the life of many programmers and various projects. Today I would like to talk about some of the pros and cons from my point of view. lambda functions . Consider the example:
 

    //C ++ 98
struct
{
bool operator () (int a, int b) const
{
return a < b;
}
} customLess;
std :: sort (s.begin (), s.end (), customLess);

 

Old kind std :: sort with an overload on its sorting algorithm. In C ++ 9? for this code, you needed to create a wrapper through the structure. With the advent of lambd, the situation has changed dramatically:


 
    //C ++
std :: sort (s.begin (), s.end (),
//Lambda begin
.[](int a, int b)
{
return a> b;
}
//End
);

 

2. STD Types


 

We all used std sometime and use it now. But std types have one big problem They are too long.


 
    int n1 = 3;
std :: vector v {? ? ? ? 4};
//Case 1
std :: vector :: iterator OldStyle = std :: find (v.begin (), v.end (), n1);
//Case 2
auto NewStyle = std :: find (v.begin (), v.end (), n1);

 

The first case: std :: find returns a type equal to std :: vector :: iterator , But we know this very well. In many projects, for example, in the same game engine X-Ray, for such iterations tayddefs were made, ala:


 
    typedef std :: vector    vec_int;
typedef vec_int :: iterator vec_int_it;

 

But I'm not a fan of this code, so it's easier to use auto , as shown in the second case.


 

3. Range-base-for loops


 

The long-awaited innovation in C ++ was the R-B-For cycles. Well, as an innovation, in C # and C ++ /CLI they already were, and the native still lagged behind
 
When we need to sort through, for example, the std :: map elements, we have to access std :: pait. But, do not forget about auto! Consider the situation by referring to the source code xray-oxygen :


 
    for (auto & entities_it: entities)
{
if (entities_it.second-> ID_Parent! = 0xffff) continue;
found = true;
Perform_destroy (entities_it.second);
break;
}

 

A good kind of cycle. Without auto it would be like this:


 
    for (std :: pair    & entities_it: entities)
{
if (entities_it.second-> ID_Parent! = 0xffff) continue;
found = true;
Perform_destroy (entities_it.second);
break;
}

 

As you understand, std :: pair will be a reference to the second subtitle, but oh well, these types are not only in STD Namespace, but also in the X-Ray itself. However, there is one more problem in these iterators, but more on this later


 

And why is it bad?


 

1. The main problem is the ambiguity of types


 

Let's say the situation, we have in the code:


 
    auto WhyIsWhy = TestPointer-> GetCrows ();    

 

A person who does not write this code, you need to quickly look at the contents of the function, run the IDE for too long, use Notepad ++. He stumbles upon this line, and receives Logic Error The search for the GetCrows function begins.


 

2. Reference to the array object or let's talk more about Range-Base-For!


 
    LimbUpdate (CIKLimb & refLimb);
{
//Code from XRay Oxygen, system of inverse kinematics, ignore,
//I take from what is at hand
for (auto it: _bone_chains)
LimbUpdate (it);
}

 

It seems that everything is fine, but! We are working not with an array element, but with a copy of the object of the element. Because of auto we are invisible that it is not a pointer, but an object. Therefore, in places where we have a one-dimensional array, I advise you to write the types completely:


 
    for (CIKLimb & it: _bone_chains)
LimbUpdate (it);

 

3. And you have x64!


 

Those who worked with writing code for AMD64 know that the compiler loves more double , rather than float . And our friend is auto it is cast during compilation in the type preferred by the program. Consider the example.


 
    auto isFloat = 1.0; //1.0f (x32) 1.0d (x64)    

 

Of course, such things are not critical, but the compiler can start to pile a bunch of type truncation warnings, which is not very pleasant, and besides, a constant write to the log slows down the assembly. But, there are situations when such casting plays a role. In cases with the natural number 'e' you need to be careful. For example:


 
    auto eps = 1e-8;    

 

In x3? this value is : ???e-09
 
In x6? this value is : ???e-08


 

Conclusion


 

Of course, it's up to you to decide where and how to use auto , but I like the full concept of static typing where it simplifies the understanding of the code.

It may be interesting

  • Comments
  • About article
  • Similar news
This publication has no comments.

weber

Author

22-09-2018, 02:24

Publication Date

Development / Programming

Category
  • Comments: 0
  • Views: 235
Complicating the standard example
Explanation of lambda expressions
What's wrong with std :: visit in
Chain of Responsibility on C ++
Personal experience: presentations and
Basics of sorting for beginners and
Write a comment
Name:*
E-Mail:


Comments

Can I find someone to write my paper for me free? At our cheap for-pay academic help service with writers across all subjects. Discover more about us here.
write a paper online free
Yesterday, 19:45

nushra45

Pretty nice post. I  just stumbled upon your weblog and wanted to say that I have really enjoyed  browsing your blog posts. After all I’ll be subscribing to your feed and I  hope you write again soon!  soaptoday
Yesterday, 17:35

Legend SEO

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
vitamin tablets
Yesterday, 17:22

taxiseo2

Tvitamin chis is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
Yesterday, 17:10

taxiseo2

КОД не работает! у event нет ни obj ни object!!! Напишите нормально! Если писать рабочие примеры, то у людей все будет работать!
Yesterday, 15:40

Бородин Степан

Adv
Website for web developers. New scripts, best ideas, programming tips. How to write a script for you here, we have a lot of information about various programming languages. You are a webmaster or a beginner programmer, it does not matter, useful articles will help to make your favorite business faster.

Login

Registration Forgot password