Results 1 to 6 of 6

Thread: Help me to use the remove_copy_if() in CPP

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    Help me to use the remove_copy_if() in CPP

    Hi, How are you. I am the student of the BSC-IT. I had learned the C++ programming language in second year of the BSC. I can know about the functions that can be in-built in the header files of the libraries of the C++ language. I must have to submit the project on the remove_copy_if() function. So, I would like to know about the remove_copy_if() function of the C++ programming language. I would like to know how can I use the remove_copy_if() function in C++ programming. Can anyone knows about the remove_copy_if() functions of C++ language.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Use the remove_copy_if()

    Hello, The remove_copy_if() function can be used in the C++ language to copy the given specified range after removing values of an element. The remove_copy_if() function can be the member of the <algorithm> header files. The following can be the syntax of the remove_copy_if() function in the C++ language :
    Code:
    template <class InptItrtr, class OtptItrtr, class Prdct>
      OtptItrtr remove_copy_if ( InptItrtr fst, InptItrtr lst,
                                      OtptItrtr rslt, Prdct prd );

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Use the remove_copy_if()

    The following program can demonstrates you that how to use the remove_copy_if() function in the programming of the C++ language while doing the coding using the remove_copy_if() function as shown below :
    Code:
    #include <iostream>
    #include <algorshm>
    #include <vector>
    using namespace std;
    bool IOd (int i)
    {
     return ((i%2)==1); 
    }
    int main ()
     {
      int mint[] = {1,2,3,4,5,6,7,8,9};          
      vector<int> mvctr (9);
      vector<int>::serator s;
      remove_copy_if (mint,mint+9,mvctr.begin(),IOd);
      cout << "mvctr contains:";
      for (s=mvctr.begin(); s!=mvctr.end(); ++s)
        cout << " " << *s;
      cout << endl;
      return 0;
    }
    The Output of the above program as :
    Code:
    mvctr contains: 2 4 6 8 0 0 0 0 0

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    The remove_copy_if() in C++

    Hello, Everybody. According to me the remove_copy_if() function can be used in the C++ language to remove the consecutive duplications that can be available in the range. The behavior of the remove_copy_if() function template can be similar to the following as :
    Code:
    template <class InptItrtr, class OtptItrtr, class Prdct>
      OtptItrtr remove_copy_if ( InptItrtr fst, InptItrtr lst,
                                      OtptItrtr rslt, Prdct prd )
    {
      for ( ; fst != lst; ++fst)
        if (!prd(*fst)) *rslt++ = *fst;
      return rslt;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Help me to use the remove_copy_if() in CPP

    The remove_copy_if() function of the C++ language can copies the given specified range of an elements [start,end) to the result, excluding the any elements for which the predicate function can returns true value. The return value of remove_copy_if() can be an iterator the end of the newer range. The remove_copy_if() function can runs in the linear time. I hope you should understood.

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    remove_copy_if() in CPP

    The code of lines that can be listed below can an illustrates you about that how could you be able to use the remove_copy_if() function in the C++ programming language :
    Code:
    class Evenval 
    {
    public:
    bool oprtr() (float val)
     {
    return (int)val %2 ? false : true;
    }
    };
    float func1(vector<float>& a, float max ) 
    {
    vector<float> b;
    vector<float>::itrtr itr = remove_copy_if (a.begin(), a.end(),
    backinsrtr(b), Evenval() );
    return 0.0;
    }

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,703,638.50873 seconds with 15 queries