Two member functions of the char_traits class

Source: Internet
Author: User
Static _ ELEM * _ clrcall_or_cdecl _ copy_s (_ ELEM * _ first1, size_t _ dest_size, const _ ELEM * _ first2, size_t _ count) {// copy [_ first1, _ first1 + _ count) to [_ first2 ,...) // _ debug_pointer (_ first1); // _ debug_pointer (_ first2); _ scl_secure_crt_validate (_ dest_size> = _ count, null); _ ELEM * _ next = _ first1; for (; 0 <_ count; -- _ count, ++ _ next, ++ _ first2) Assign (* _ next, * _ first2); Return (_ first1 );}

Static _ ELEM * _ clrcall_or_cdecl _ move_s (_ ELEM * _ first1, size_t _ dest_size, const _ ELEM * _ first2, size_t _ count) {// move [_ first1, _ first1 + _ count) to [_ first2 ,...) // _ debug_pointer (_ first1); // _ debug_pointer (_ first2); _ scl_secure_crt_validate (_ dest_size> = _ count, null); _ ELEM * _ next = _ first1; if (_ first2 <_ next & _ next <_ first2 + _ count) // the same string for (_ next + = _ count, _ first2 + = _ count; 0 <_ count; -- _ count) Assign (* -- _ next, * -- _ first2); elsefor (; 0 <_ count; -- _ count, ++ _ next, ++ _ first2) Assign (* _ next, * _ first2); Return (_ first1 );}

The _ copy_s and _ move_s functions are very similar. The difference is that _ move_s judges multiple identical strings. If the string is the same, it is copied from the reverse order of the character. If you copy the data in sequence, overwriting may occur.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.