#include <iostream>
#include <vector>
#include <stdlib.h>

template <typename T>
void swap(T& a, T& b) {
    T tmp = b;
    b = a;
    a = tmp;    
}

template <typename T>
T bubblesort(T& vec) {
    auto f = vec.begin();
    auto s = vec.begin();
    ++s;
    bool swapped = false;
    while (s != vec.end()) {
	if (*f > *s) {
	    swap(*f, *s);
	    swapped = true;
	}
	++f; ++s;
    }
    if (swapped) {
	bubblesort(vec);
    }
    return vec;
}

#include <iostream>
#include <vector>
#include <stdlib.h>

template <typename T>
void swap(T& a, T& b) {
    T tmp = b;
    b = a;
    a = tmp;    
}

template <typename T>
void bubblesort(T& vec) {
    auto f = vec.begin();
    auto s = vec.begin();
    ++s;
    bool swapped = false;
    while (s != vec.end()) {
	if (*f > *s) {
	    swap(*f, *s);
	    swapped = true;
	}
	++f; ++s;
    }
    if (swapped) {
	bubblesort(vec);
    }
}

--- 
+++ 
@@ -10,7 +10,7 @@
 }
 
 template <typename T>
-void bubblesort(T& vec) {
+T bubblesort(T& vec) {
     auto f = vec.begin();
     auto s = vec.begin();
     ++s;
@@ -25,4 +25,5 @@
     if (swapped) {
 	bubblesort(vec);
     }
+    return vec;
 }
Bubblesort: Return the sorted object as well as sort it in-place
