I am having this error in my program error C2143: syntax error : missing ',' before ':', I am using Visual c++ express 2010 and i think C++11 dosent support in VC 2010.
Can somone please modify this code and explain how to revert this for loop in traditional for loop ? ouFlexSignalInfo is a list data type from c++ stl
for(auto ouSignalInfo : ouFlexSignalInfo) //C++11;
{
SSignalInfo ouSignal;
ouSignal.m_omEnggValue = ouSignalInfo.m_omEnggValue.c_str();
ouSignal.m_omRawValue = ouSignalInfo.m_omRawValue.c_str();
ouSignal.m_omSigName = ouSignalInfo.m_omSigName.c_str();
ouSignal.m_omUnit = ouSignalInfo.m_omUnit.c_str();
ouSignal.m_msgName=ouFrame.m_strFrameName.c_str();
SigInfoArray.Add(ouSignal);
}
it is roughly equivalent to:
auto iterBegin = std::begin(ouFlexSignalInfo);
auto iterEnd = std::end(ouFlexSignalInfo);
for(; iterBegin != iterEnd; ++iterBegin)
{
auto ouSignalInfo = *iterBegin;
//the rest of body
}
the iterBegin and iterEnd are iterators returned from the ouFlexSignalInfo members begin and end.
This kind of loop works for everything that has begin and end members
If you use MS VC++ 2010 then the compiler supports a MS language extension for the range-based for loop. The code will look the following way
for each ( auto ouSignalInfo in ouFlexSignalInfo )
{
SSignalInfo ouSignal;
ouSignal.m_omEnggValue = ouSignalInfo.m_omEnggValue.c_str();
ouSignal.m_omRawValue = ouSignalInfo.m_omRawValue.c_str();
ouSignal.m_omSigName = ouSignalInfo.m_omSigName.c_str();
ouSignal.m_omUnit = ouSignalInfo.m_omUnit.c_str();
ouSignal.m_msgName=ouFrame.m_strFrameName.c_str();
SigInfoArray.Add(ouSignal);
}
Or it would be better to write
for each ( const auto &ouSignalInfo in ouFlexSignalInfo )
{
SSignalInfo ouSignal;
ouSignal.m_omEnggValue = ouSignalInfo.m_omEnggValue.c_str();
ouSignal.m_omRawValue = ouSignalInfo.m_omRawValue.c_str();
ouSignal.m_omSigName = ouSignalInfo.m_omSigName.c_str();
ouSignal.m_omUnit = ouSignalInfo.m_omUnit.c_str();
ouSignal.m_msgName=ouFrame.m_strFrameName.c_str();
SigInfoArray.Add(ouSignal);
}
As the type of ouFlexSignalInfo is unknown then you can use iterators. For example
#include <iterator>
for ( auto it = std::begin( ouFlexSignalInfo ); it != std::end( ouFlexSignalInfo ); ++it )
{
SSignalInfo ouSignal;
ouSignal.m_omEnggValue = it->m_omEnggValue.c_str();
ouSignal.m_omRawValue = it->m_omRawValue.c_str();
ouSignal.m_omSigName = it->m_omSigName.c_str();
ouSignal.m_omUnit = it->m_omUnit.c_str();
ouSignal.m_msgName = ouFrame.m_strFrameName.c_str();
SigInfoArray.Add( ouSignal );
}
Related
Here is a basic sample converting them and dumping the result into a mesh:
// FloatGrid to Vec3SGrid
openvdb::Vec3SGrid::Ptr Vec3SGrid = openvdb::Vec3SGrid::create();
Vec3SGrid->setTransform( floatGridA->transformPtr());
Vec3SGrid->tree().root().setBackground(openvdb::Vec3f(floatGridA->background()),true);
for (auto itAll = floatGridA ->cbeginValueOn(); itAll; ++itAll) {
auto pos = itAll.getCoord();
auto valueAll = itAll.getValue();
auto Vec3s = Vec3SGrid->tree().getValue(pos);
Vec3s[0] = valueAll;
Vec3SGrid->tree().setValue(pos, Vec3s);
}
// Back to FloatGrid
openvdb::FloatGrid::Ptr floatGridB = openvdb::FloatGrid::create();
floatGridB->setTransform( Vec3SGrid->transformPtr());
floatGridB->tree().root().setBackground(Vec3SGrid->background()[0], true);
for (auto it = grid->cbeginValueOn(); it; ++it) {
auto pos = it.getCoord();
auto Vec3s = it.getValue();
floatGridB->tree().setValue(pos, Vec3s[0]);
}
OpenVDBMesh meshA, meshB;
openvdb::tools::volumeToMesh(*floatGridA , meshA.points, meshA.faces, meshA.quads, iso, adapt, flag_relax);
openvdb::tools::volumeToMesh(*floatGridB , meshB.points, meshB.faces, meshB.quads, iso, adapt, flag_relax);
Unfortunately the besides I've copied transform too, the result on both meshes are different.
Any idea on that? thank you!
Using the official TDLib C++ example, I'm trying to send a message with formatted markdown text.
Here's my code:
auto send_message = td_api::make_object<td_api::sendMessage>();
send_message->chat_id_ = -1001424068198;
auto message_content = td_api::make_object<td_api::inputMessageText>();
std::string text = "Hello! **how are u?**";
message_content->text_ = td_api::make_object<td_api::formattedText>();
message_content->text_->text_ = std::move(text);
send_message->input_message_content_ = std::move(message_content);
send_query(std::move(send_message), {});
I expect to see "Hello! how are u?" but the message comes as it is written in the code, without markdown formatting applied.
I spent hours on google trying to figure out how to force TDLib to parse it.
UPDATE: SOLVED!
Thanks Azeem for help!
Using this example, the following code should send the parsed message (tested in VS 2019)
void sendMsg(INT64 chatID, INT64 ReplyTo, const char* textMsg) {
const std::string text = textMsg;
auto textParseMarkdown = td_api::make_object<td_api::textParseModeMarkdown>(2);
auto parseTextEntities = td_api::make_object<td_api::parseTextEntities>(text, std::move(textParseMarkdown));
td::Client::Request parseRequest{ 123, std::move(parseTextEntities) };
auto parseResponse = td::Client::execute(std::move(parseRequest));
if (parseResponse.object->get_id() == td_api::formattedText::ID) {
auto formattedText = td_api::make_object<td_api::formattedText>();
formattedText = td_api::move_object_as<td_api::formattedText>(parseResponse.object);
auto send_message = td_api::make_object<td_api::sendMessage>();
send_message->chat_id_ = chatID;
auto message_content = td_api::make_object<td_api::inputMessageText>();
message_content->text_ = std::move(formattedText);
send_message->input_message_content_ = std::move(message_content);
send_message->reply_to_message_id_ = ReplyTo;
send_query(std::move(send_message), {});
}
}
You can use td_api::textParseModeMarkdown, td_api::parseTextEntities and td::Client::execute() like this:
using namespace td;
const std::string text = "*bold* _italic_ `code`";
auto textParseMarkdown = td_api::make_object<td_api::textParseModeMarkdown>( 2 );
auto parseTextEntities = td_api::make_object<td_api::parseTextEntities>( text, std::move( textParseMarkdown ) );
td::Client::Request parseRequest { 123, std::move( parseTextEntities ) };
auto parseResponse = td::Client::execute( std::move( parseRequest ) );
auto formattedText = td_api::make_object<td_api::formattedText>();
if ( parseResponse.object->get_id() == td_api::formattedText::ID )
{
formattedText = td_api::move_object_as<td_api::formattedText>( parseResponse.object );
}
else
{
std::vector<td_api::object_ptr<td_api::textEntity>> entities;
formattedText = td_api::make_object<td_api::formattedText>( text, std::move(entities) );
}
std::cout << td_api::to_string( formattedText ) << '\n';
For debugging purposes, you can use td_api::to_string() to dump the contents of an object. For example, dumping parseTextEntities like this:
std::cout << td_api::to_string( parseTextEntities ) << '\n';
would give this:
parseTextEntities {
text = "*bold* _italic_ `code`"
parse_mode = textParseModeMarkdown {
version = 2
}
}
I need to write the following code in Scala (it is actually in C++). I have tried many ways but it still doesn't work. Any ideas?
pair<HashClosed::const_iterator, HashClosed::const_iterator> p =
closedItemsets.equal_range(pos1->second.myTidSum);
for ( HashClosed::const_iterator pos = p.first; pos != p.second; ++pos ) {
if ( pos->second.first == x->second.first ){}
Thx everyone , I have find the solution , this code in c++ is written as following in scala
for (pos <-pos.get(p._1) if pos != p._2)
{
pos._2.toMap
x._2.toMap
if(pos._1 == x._1)
{}
}
TGuildMemberContainer::iterator it;
if ((it = m_member.find (p->dwPID)) == m_member.end())
{
m_member.insert (std::make_pair (p->dwPID, TGuildMember (p->dwPID, p->bGrade, p->isGeneral, p->bJob, p->bLevel, p->dwOffer, p->szName)));
}
else
{
TGuildMember& r_gm = it->second;
r_gm.pid = p->dwPID;
r_gm.grade = p->bGrade;
r_gm.job = p->bJob;
r_gm.offer_exp = p->dwOffer;
r_gm.is_general = p->isGeneral;
}
Hi, i want to apply auto transform intro my codes, but i'm stuck.
If i add auto
if (auto it = m_member.find (p->dwPID) == m_member.end())
The auto assign a bool
if ( bool it = m_member.find (p->dwPID) == m_member.end())
This say Visual Studio intelisense.
My question, why auto assign me a bool and not the corect iteration range ?
Because the compiler is parsing it as:
if (auto it = (m_member.find (p->dwPID) == m_member.end()))
which is a boolean expression. You can't write it as:
if ((auto it = m_member.find (p->dwPID)) == m_member.end())
because putting the variable declaration inside brackets like that is not allowed.
I find creating variables in if hard to read. Just use:
const auto it = m_member.find(p->dwPID);
if (it == m_member.end())
...
In C++17, this can be done as
if (auto it = m_member.find (p->dwPID); it == m_member.end())
which avoids the scope problem mentioned in the other answer.
In the following code, I try to replace operand(s) of an LLVM instructions. However it doesn't work and nothing is changed. Any idea how to solve this?
for (OI = insn->op_begin(), OE = insn->op_end(); OI != OE; ++OI)
{
Value *val = *OI;
iter = mapClonedAndOrg.find( val );
if( iter != mapClonedAndOrg.end( ) )
{
// Here I try to replace the operand, to no effect!
val = (Value*)iter->second.PN;
}
}
You should use the iterator OI to replace it, instead of the local pointer val. So it should be like this.
for (OI = insn->op_begin(), OE = insn->op_end(); OI != OE; ++OI)
{
Value *val = *OI;
iter = mapClonedAndOrg.find( val );
if( iter != mapClonedAndOrg.end( ) )
{
*OI = (Value*)iter->second.PN;
}
}
What you are doing is simply making a local pointer point to something else, you don't actually change what it points to. For that you need to use the dereferencing operator *:
*val = *((Value*) iter->second.PN);