Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8115239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:24:19+00:00 2026-06-06T03:24:19+00:00

std::vector<bool> reprVectors::encode(std::vector<float> input){ std::vector<float> distance; for(size_t i=0;i<this->reprVectorsList.size();i++){ distance.push_back(distBtw(input,this->reprVectorsList[i])); } std::vector<float>::iterator it= min_element(distance.begin(),distance.end()); return this->reprVectorsList[it]->code;

  • 0
    std::vector<bool> reprVectors::encode(std::vector<float> input){
    std::vector<float> distance;
    for(size_t i=0;i<this->reprVectorsList.size();i++){
            distance.push_back(distBtw(input,this->reprVectorsList[i]));
    }
    std::vector<float>::iterator it= min_element(distance.begin(),distance.end());

    return this->reprVectorsList[it]->code;
}


float reprVectors::distBtw(std::vector<float> input, Node* node){
    double distance=0;
    for(size_t i=0;i<node->valuesInDim.size();i++){
        distance = distance +
                    pow((node->valuesInDim[i]-input[i]),2);
    }
    return (float)pow(distance,0.5);
}

it iterator gives me the minimum distance in the distance vector.
How do I find the corresponding position in my reprVectorList?
how can I get an int/size_t value from it iterator returned by min_element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:24:21+00:00Added an answer on June 6, 2026 at 3:24 am

    You can use std::distance:

    auto index = std::distance(distance.begin(), it);
    

    This approach is favourable to performing arithmetic operations on iterators, since it is valid for all operator types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to initialize a vector of pairs with something like this std::vector< std::pair<bool,
I'm trying to figure out what this piece of code does: std::vector<std::vector<bool> > visited(rows,
std::vector<Foo> vec; Foo foo(...); assert(vec.size() == 0); vec.reserve(100); // I've reserved 100 elems vec[50]
std::vector<const int> vci; vci.push_back(1); vci[0] = 2; With the element type being const int
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
Suppose I want to use std::lower_bound on a std::vector of pointers like this: struct
I have the following code snippet: std::vector< boost::shared_ptr<Foo> >::iterator it; it = returnsAnIterator(); //
Greetings, Any input on a way to divide a std::vector into two equal parts
#include<iostream> #include<vector> std::vector<std::string> vector1; int main() { vector1.push_back(adadad); std::vector<std::string> vector2; vector2.push_back(adadd); if (vector1==vector2) {
bool Connection::Receive(){ std::vector<uint8_t> buf(1000); boost::asio::async_read(socket_,boost::asio::buffer(buf,1000), boost::bind(&Connection::handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); int rcvlen=buf.size(); ByteBuffer b((std::shared_ptr<uint8_t>)buf.data(),rcvlen); if(rcvlen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.