Skip to content

Commit

Permalink
use C++11 builtin range based for loop (#3522)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Oct 26, 2015
1 parent 27e6c56 commit a2254ab
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
7 changes: 3 additions & 4 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -13599,10 +13599,9 @@ template algStmtForGeneric_impl(Exp exp, Ident iterator, String type,
// '<%iterName%> = *(<%arrayType%>_element_addr1(&<%evar%>, 1, <%tvar%>));'
<<
<%preExp%>
<%type%> <%iterName%>;
BOOST_FOREACH(<%iterName%>, <%evar%>) {
<%body%>
}
FOREACH(<%type%> <%iterName%>, <%evar%>) {
<%body%>
}
>>

end algStmtForGeneric_impl;
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
Expand Up @@ -40,7 +40,7 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa

ptree modelDescription = tree.get_child("ModelDescription");

BOOST_FOREACH(ptree::value_type const& vars, modelDescription.get_child("ModelVariables"))
FOREACH(ptree::value_type const& vars, modelDescription.get_child("ModelVariables"))
{
if(vars.first == "ScalarVariable")
{
Expand All @@ -67,7 +67,7 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
bool isAlias = aliasInfo.compare("alias") == 0;
bool isNegatedAlias = aliasInfo.compare("negatedAlias") == 0;

BOOST_FOREACH(ptree::value_type const& var, vars.second.get_child(""))
FOREACH(ptree::value_type const& var, vars.second.get_child(""))
{

if(var.first == "Real")
Expand Down
3 changes: 1 addition & 2 deletions SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -286,10 +286,9 @@ void SimController::Start(SimSettings simsettings, string modelKey)
history->getOutputResults(Ro);
vector<string> output_names;
history->getOutputNames(output_names);
string name;
int j=0;

BOOST_FOREACH(name,output_names)
FOREACH(string& name, output_names)
{
ublas::vector<double> o_j;
o_j = ublas::row(Ro,j);
Expand Down
Expand Up @@ -424,8 +424,7 @@ void SystemDefaultImplementation::getRHS(double* f)
void SystemDefaultImplementation::intDelay(vector<unsigned int> expr, vector<double> delay_max)
{
_time_buffer.set_capacity(1024);
unsigned int expr_id;
BOOST_FOREACH(expr_id,expr)
FOREACH(unsigned int expr_id, expr)
{
buffer_type delay_buffer(1024);
_delay_buffer[expr_id]=delay_buffer;
Expand Down
Expand Up @@ -102,7 +102,7 @@ class BufferReaderWriter : public ContainerManager
}
try
{
/*BOOST_FOREACH(i,indices)*/
/*FOREACH(i,indices)*/
for(i=0;i<n;i++)
{
for(j=0;j<m;++j)
Expand Down Expand Up @@ -221,11 +221,10 @@ class BufferReaderWriter : public ContainerManager
{
try
{
std::pair<double,unsigned long> i;
BOOST_FOREACH(i, _time_entries)
typedef std::pair<double, unsigned long> pair_double_ulong;
FOREACH(pair_double_ulong i, _time_entries)
{
time.push_back(i.first);

}
}
catch(std::exception& ex)
Expand Down
8 changes: 7 additions & 1 deletion SimulationRuntime/cpp/Include/Core/Modelica.h
Expand Up @@ -14,7 +14,6 @@

#include <boost/lexical_cast.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/foreach.hpp>
#define BOOST_UBLAS_SHALLOW_ARRAY_ADAPTOR
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
Expand Down Expand Up @@ -60,6 +59,9 @@ using namespace boost::numeric;
#include <unordered_map>
#include <unordered_set>

// builtin range based for loop
#define FOREACH(element, range) for(element : range)

// builtin list initializers
#define LIST_OF {
#define LIST_SEP ,
Expand Down Expand Up @@ -112,6 +114,7 @@ using namespace boost::numeric;
using boost::make_tuple;
using boost::minmax_element;
#endif
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/array.hpp>
#include <boost/math/special_functions/trunc.hpp>
Expand All @@ -138,6 +141,9 @@ using namespace boost::numeric;
using boost::dynamic_pointer_cast;
#endif //USE_THREAD

// boost range based for loop
#define FOREACH BOOST_FOREACH

// boost list initializers
#define LIST_OF boost::assign::list_of(
#define LIST_SEP )(
Expand Down

0 comments on commit a2254ab

Please sign in to comment.