Sorting the includes

Hello! i was looking at the new feature of Resharper that allows to sort the includes in the source file.

In our team we follow this order of includes (from most specific to more general ones):

  1. precompiled header (if used)
  2. main header for the source
  3. headers from the same project
  4. headers from other our projects in the solution
  5. headers from third-party
  6. headers from std

1-3 should use quotes and only relative paths
4-6 should use angle brackets and paths from the directories specified in the project settings

So the order is something like this one:

#include "Context.h"     // Main header

#include "FabViewer.h"  // Same project
#include "View.h"       // Same project

#include <Algo/VTKWrapper/PolyDataOperator/GVWPolyDataSerializer.h>  // From the project Algo
#include <Algo/VTKWrapper/Core/GVWPolyDataWrapper.h>                 // From the project Algo
#include <Algo/VTKWrapper/Core/PolyDataHelper.h>                     // From the project Algo

#include <TraceData/TraceData.h>                                     // From the project TraceData

#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/property_tree/json_parser.hpp>

#include <glog/logging.h>

#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QTreeWidgetItem>

#include <array>

Can Resharper C++ help me in sorting the headers according this order?

 

1 comment
Comment actions Permalink

Hello,

R++ splits headers into groups according to rules based on regular expressions. If you can distinguish between different groups with a regular expression then sorting should work for you.

0

Please sign in to leave a comment.